smplkit

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 10 Imported by: 0

README

smplkit Go SDK

The official Go client for the smplkit platform.

Requirements

Go 1.21 or later.

Installation

go get github.com/smplkit/go-sdk

Authentication

Create a client with your API key (prefixed sk_api_):

client := smplkit.NewClient("sk_api_your_key_here")

The key is sent as a Bearer token on every request. Never log or expose your API key.

Quick Start

package main

import (
	"context"
	"errors"
	"fmt"
	"log"

	smplkit "github.com/smplkit/go-sdk"
)

func main() {
	client := smplkit.NewClient("sk_api_your_key_here")

	ctx := context.Background()

	// List all configs
	configs, err := client.Config().List(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for _, cfg := range configs {
		fmt.Printf("%s: %s\n", cfg.Key, cfg.Name)
	}

	// Get a config by key
	cfg, err := client.Config().GetByKey(ctx, "my-service")
	if err != nil {
		var notFound *smplkit.SmplNotFoundError
		if errors.As(err, &notFound) {
			fmt.Println("Config not found")
			return
		}
		log.Fatal(err)
	}
	fmt.Printf("Config: %s (values: %v)\n", cfg.Name, cfg.Values)

	// Create a config
	key := "new-service"
	newCfg, err := client.Config().Create(ctx, smplkit.CreateConfigParams{
		Name:   "New Service",
		Key:    &key,
		Values: map[string]interface{}{"log_level": "info"},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Created: %s\n", newCfg.ID)

	// Delete a config
	if err := client.Config().Delete(ctx, newCfg.ID); err != nil {
		log.Fatal(err)
	}
}

Configuration

Use functional options to customise the client:

client := smplkit.NewClient("sk_api_...",
	smplkit.WithBaseURL("https://custom.example.com"),
	smplkit.WithTimeout(10 * time.Second),
	smplkit.WithHTTPClient(myHTTPClient),
)

Error Handling

All SDK errors embed SmplError and support errors.Is() / errors.As():

Error Type HTTP Status Description
SmplNotFoundError 404 Resource does not exist
SmplConflictError 409 Operation conflicts with state
SmplValidationError 422 Server rejected the request
SmplConnectionError --- Network request failed
SmplTimeoutError --- Request exceeded timeout
cfg, err := client.Config().GetByKey(ctx, "missing")
if err != nil {
	var notFound *smplkit.SmplNotFoundError
	if errors.As(err, &notFound) {
		// handle 404
	}
	var base *smplkit.SmplError
	if errors.As(err, &base) {
		fmt.Println(base.StatusCode, base.ResponseBody)
	}
}

Documentation

Full documentation is available at docs.smplkit.com.

Contributing

This project is in its initial development phase. Contributions are not currently accepted, but feel free to open issues for bugs or feature requests.

License

MIT --- see LICENSE.

Documentation

Overview

Package smplkit provides a Go client for the smplkit platform.

The SDK follows a two-layer architecture: auto-generated types live in internal/generated, while this package provides the hand-crafted public API.

Quick start:

client := smplkit.NewClient("sk_api_...")
cfg, err := client.Config().GetByKey(ctx, "my-service")
if err != nil {
    var notFound *smplkit.SmplNotFoundError
    if errors.As(err, &notFound) {
        // handle not found
    }
    return err
}
fmt.Println(cfg.Name)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the top-level entry point for the smplkit SDK.

Create one with NewClient and access sub-clients via accessor methods:

client := smplkit.NewClient("sk_api_...")
cfgs, err := client.Config().List(ctx)

func NewClient

func NewClient(apiKey string, opts ...ClientOption) *Client

NewClient creates a new smplkit API client.

The apiKey is used for Bearer token authentication on every request. Use ClientOption functions to customize the base URL, timeout, or HTTP client.

func (*Client) Config

func (c *Client) Config() *ConfigClient

Config returns the sub-client for config management operations.

type ClientOption

type ClientOption func(*clientConfig)

ClientOption configures the Client. Pass options to NewClient.

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL overrides the default API base URL.

func WithHTTPClient

func WithHTTPClient(c *http.Client) ClientOption

WithHTTPClient replaces the default HTTP client entirely. When set, the WithTimeout option is ignored because the caller controls the client.

func WithTimeout

func WithTimeout(d time.Duration) ClientOption

WithTimeout sets the HTTP request timeout. The default is 30 seconds.

type Config

type Config struct {
	// ID is the unique identifier (UUID) of the config.
	ID string
	// Key is the human-readable config key (e.g. "user_service").
	Key string
	// Name is the display name for the config.
	Name string
	// Description is an optional description of the config.
	Description *string
	// Parent is the parent config UUID, or nil for root configs.
	Parent *string
	// Values holds the base configuration values.
	Values map[string]interface{}
	// Environments maps environment names to their value overrides.
	Environments map[string]map[string]interface{}
	// CreatedAt is the creation timestamp.
	CreatedAt *time.Time
	// UpdatedAt is the last-modified timestamp.
	UpdatedAt *time.Time
}

Config represents a configuration resource from the smplkit platform.

type ConfigClient

type ConfigClient struct {
	// contains filtered or unexported fields
}

ConfigClient provides CRUD operations for config resources. Obtain one via Client.Config().

func (*ConfigClient) Create

func (c *ConfigClient) Create(ctx context.Context, params CreateConfigParams) (*Config, error)

Create creates a new config resource.

func (*ConfigClient) Delete

func (c *ConfigClient) Delete(ctx context.Context, id string) error

Delete removes a config by its UUID. Returns nil on success (HTTP 204).

func (*ConfigClient) Get

func (c *ConfigClient) Get(ctx context.Context, opts ...GetOption) (*Config, error)

Get retrieves a single config using functional options. Exactly one of WithKey or WithID must be provided.

cfg, err := client.Config().Get(ctx, smplkit.WithKey("my-service"))
cfg, err := client.Config().Get(ctx, smplkit.WithID("uuid-here"))

func (*ConfigClient) GetByID

func (c *ConfigClient) GetByID(ctx context.Context, id string) (*Config, error)

GetByID retrieves a config by its UUID.

func (*ConfigClient) GetByKey

func (c *ConfigClient) GetByKey(ctx context.Context, key string) (*Config, error)

GetByKey retrieves a config by its human-readable key. Uses the list endpoint with a filter[key] query parameter and returns the first match, or SmplNotFoundError if none match.

func (*ConfigClient) List

func (c *ConfigClient) List(ctx context.Context) ([]*Config, error)

List returns all configs for the account.

type CreateConfigParams

type CreateConfigParams struct {
	// Name is the display name (required).
	Name string
	// Key is the human-readable key. Auto-generated by the server if nil.
	Key *string
	// Description is an optional description.
	Description *string
	// Parent is the parent config UUID.
	Parent *string
	// Values holds the initial base values.
	Values map[string]interface{}
}

CreateConfigParams holds the parameters for creating a new config.

type GetOption

type GetOption func(*getConfig)

GetOption configures a Get request. Use WithKey or WithID to specify the lookup strategy.

func WithID

func WithID(id string) GetOption

WithID returns a GetOption that looks up a config by its UUID.

func WithKey

func WithKey(key string) GetOption

WithKey returns a GetOption that looks up a config by its human-readable key.

type SmplConflictError

type SmplConflictError struct {
	SmplError
}

SmplConflictError is raised when an operation conflicts with current state (HTTP 409).

func (*SmplConflictError) Error

func (e *SmplConflictError) Error() string

Error implements the error interface.

func (*SmplConflictError) Unwrap

func (e *SmplConflictError) Unwrap() error

Unwrap returns the embedded SmplError for errors.Is/errors.As support.

type SmplConnectionError

type SmplConnectionError struct {
	SmplError
}

SmplConnectionError is raised when a network request fails.

func (*SmplConnectionError) Error

func (e *SmplConnectionError) Error() string

Error implements the error interface.

func (*SmplConnectionError) Unwrap

func (e *SmplConnectionError) Unwrap() error

Unwrap returns the embedded SmplError for errors.Is/errors.As support.

type SmplError

type SmplError struct {
	Message      string
	StatusCode   int
	ResponseBody string
}

SmplError is the base error type for all smplkit SDK errors. All specific error types embed SmplError, so errors.As(err, &SmplError{}) will match any SDK error.

func (*SmplError) Error

func (e *SmplError) Error() string

Error implements the error interface.

type SmplNotFoundError

type SmplNotFoundError struct {
	SmplError
}

SmplNotFoundError is raised when a requested resource does not exist (HTTP 404).

func (*SmplNotFoundError) Error

func (e *SmplNotFoundError) Error() string

Error implements the error interface.

func (*SmplNotFoundError) Unwrap

func (e *SmplNotFoundError) Unwrap() error

Unwrap returns the embedded SmplError for errors.Is/errors.As support.

type SmplTimeoutError

type SmplTimeoutError struct {
	SmplError
}

SmplTimeoutError is raised when an operation exceeds its timeout.

func (*SmplTimeoutError) Error

func (e *SmplTimeoutError) Error() string

Error implements the error interface.

func (*SmplTimeoutError) Unwrap

func (e *SmplTimeoutError) Unwrap() error

Unwrap returns the embedded SmplError for errors.Is/errors.As support.

type SmplValidationError

type SmplValidationError struct {
	SmplError
}

SmplValidationError is raised when the server rejects a request due to validation errors (HTTP 422).

func (*SmplValidationError) Error

func (e *SmplValidationError) Error() string

Error implements the error interface.

func (*SmplValidationError) Unwrap

func (e *SmplValidationError) Unwrap() error

Unwrap returns the embedded SmplError for errors.Is/errors.As support.

Directories

Path Synopsis
Config Showcase — end-to-end walkthrough of the Smpl Config Go SDK.
Config Showcase — end-to-end walkthrough of the Smpl Config Go SDK.
internal
generated/app
Package app contains auto-generated types from the app OpenAPI spec.
Package app contains auto-generated types from the app OpenAPI spec.
generated/config
Package config contains auto-generated types from the config OpenAPI spec.
Package config contains auto-generated types from the config OpenAPI spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL