client

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

pk-client

Public Go client primitives for PlatformKit APIs.

This repo intentionally stays transport-focused and free of private septagon-dev imports. Pro clients can wrap these types with generated SDKs, authentication providers, telemetry, or hosted defaults.

Current Surface

  • generic CRUD client wrapper
  • HTTP transport with headers, query params, bearer/API-key auth, and timeouts
  • transport-safe request and response DTOs

Verify

make verify
make staticcheck

Documentation

Overview

Package client provides typed clients for PlatformKit-style CRUD APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int    `json:"status_code"`
	Message    string `json:"message"`
	ErrorMsg   string `json:"error,omitempty"`
	Body       []byte `json:"-"`
}

func (*APIError) Error

func (e *APIError) Error() string

type BulkCreateInput

type BulkCreateInput[T any] struct {
	Items []T `json:"items"`
}

type BulkDeleteInput

type BulkDeleteInput struct {
	IDs []string `json:"ids"`
}

type BulkError

type BulkError struct {
	ID    string `json:"id"`
	Error string `json:"error"`
}

type BulkMetadata

type BulkMetadata struct {
	TotalCount     int `json:"total_count"`
	SucceededCount int `json:"succeeded_count"`
	FailedCount    int `json:"failed_count"`
}

type BulkResponse

type BulkResponse[T any] struct {
	Succeeded []T           `json:"succeeded"`
	Failed    []BulkError   `json:"failed"`
	Metadata  *BulkMetadata `json:"metadata,omitempty"`
}

type BulkUpdateInput

type BulkUpdateInput[T any] struct {
	Items []T `json:"items"`
}

type CRUDTransport

type CRUDTransport[T any] interface {
	Transport

	Create(ctx context.Context, input *CreateInput[T]) (*ItemResponse[T], error)
	GetByID(ctx context.Context, id string) (*ItemResponse[T], error)
	List(ctx context.Context, params *ListParams) (*ListResponse[T], error)
	Update(ctx context.Context, id string, input *UpdateInput[T]) (*ItemResponse[T], error)
	PartialUpdate(ctx context.Context, id string, input *PartialUpdateInput) (*ItemResponse[T], error)
	Delete(ctx context.Context, id string) error

	BulkCreate(ctx context.Context, input *BulkCreateInput[T]) (*BulkResponse[T], error)
	BulkUpdate(ctx context.Context, input *BulkUpdateInput[T]) (*BulkResponse[T], error)
	BulkDelete(ctx context.Context, ids []string) error

	Export(ctx context.Context, params ExportParams) ([]byte, error)
	Import(ctx context.Context, data []byte, format string) (*ImportResponse, error)
}

CRUDTransport defines the transport-safe CRUD surface exposed by PlatformKit.

type Client

type Client[T any] struct {
	// contains filtered or unexported fields
}

Client provides transport-agnostic CRUD operations for PlatformKit APIs.

func New

func New[T any](transport CRUDTransport[T]) *Client[T]

func NewHTTP

func NewHTTP[T any](config *HTTPConfig) (*Client[T], error)

func (*Client[T]) BulkCreate

func (c *Client[T]) BulkCreate(ctx context.Context, input BulkCreateInput[T]) (*BulkResponse[T], error)

func (*Client[T]) BulkDelete

func (c *Client[T]) BulkDelete(ctx context.Context, ids []string) error

func (*Client[T]) BulkUpdate

func (c *Client[T]) BulkUpdate(ctx context.Context, input BulkUpdateInput[T]) (*BulkResponse[T], error)

func (*Client[T]) Create

func (c *Client[T]) Create(ctx context.Context, input CreateInput[T]) (*ItemResponse[T], error)

func (*Client[T]) Delete

func (c *Client[T]) Delete(ctx context.Context, id string) error

func (*Client[T]) Export

func (c *Client[T]) Export(ctx context.Context, params ExportParams) ([]byte, error)

func (*Client[T]) GetByID

func (c *Client[T]) GetByID(ctx context.Context, id string) (*ItemResponse[T], error)

func (*Client[T]) Import

func (c *Client[T]) Import(ctx context.Context, data []byte, format string) (*ImportResponse, error)

func (*Client[T]) List

func (c *Client[T]) List(ctx context.Context, params ListParams) (*ListResponse[T], error)

func (*Client[T]) PartialUpdate

func (c *Client[T]) PartialUpdate(ctx context.Context, id string, input PartialUpdateInput) (*ItemResponse[T], error)

func (*Client[T]) Transport

func (c *Client[T]) Transport() CRUDTransport[T]

func (*Client[T]) Update

func (c *Client[T]) Update(ctx context.Context, id string, input UpdateInput[T]) (*ItemResponse[T], error)

func (*Client[T]) WithTransport

func (c *Client[T]) WithTransport(transport CRUDTransport[T]) *Client[T]

type Config

type Config interface {
	Validate() error
	GetType() TransportType
}

Config validates transport-specific configuration.

type CreateInput

type CreateInput[T any] struct {
	Body T `json:"body"`
}

type ExportParams

type ExportParams struct {
	Format string   `json:"format,omitempty"`
	Filter *Filter  `json:"filter,omitempty"`
	Fields []string `json:"fields,omitempty"`
}

type Filter

type Filter struct {
	Field    string   `json:"field,omitempty"`
	Operator string   `json:"operator,omitempty"`
	Value    any      `json:"value,omitempty"`
	All      []Filter `json:"all,omitempty"`
	Any      []Filter `json:"any,omitempty"`
	Not      *Filter  `json:"not,omitempty"`
}

type HTTPConfig

type HTTPConfig struct {
	BaseURL     string            `json:"base_url"`
	EntityPath  string            `json:"entity_path"`
	APIKey      string            `json:"api_key,omitempty"`
	Timeout     time.Duration     `json:"timeout"`
	Headers     map[string]string `json:"headers,omitempty"`
	QueryParams map[string]string `json:"query_params,omitempty"`
	HTTPClient  *http.Client      `json:"-"`
}

func NewHTTPConfig

func NewHTTPConfig(baseURL, entityPath string, options ...Option) *HTTPConfig

func (*HTTPConfig) GetType

func (c *HTTPConfig) GetType() TransportType

func (*HTTPConfig) Validate

func (c *HTTPConfig) Validate() error

func (*HTTPConfig) WithBearerToken

func (c *HTTPConfig) WithBearerToken(token string) *HTTPConfig

func (*HTTPConfig) WithHTTPClient

func (c *HTTPConfig) WithHTTPClient(client *http.Client) *HTTPConfig

func (*HTTPConfig) WithHeader

func (c *HTTPConfig) WithHeader(key, value string) *HTTPConfig

func (*HTTPConfig) WithQueryParam

func (c *HTTPConfig) WithQueryParam(key, value string) *HTTPConfig

type HTTPTransport

type HTTPTransport[T any] struct {
	// contains filtered or unexported fields
}

func NewHTTPTransport

func NewHTTPTransport[T any](config *HTTPConfig) (*HTTPTransport[T], error)

func (*HTTPTransport[T]) BulkCreate

func (t *HTTPTransport[T]) BulkCreate(ctx context.Context, input *BulkCreateInput[T]) (*BulkResponse[T], error)

func (*HTTPTransport[T]) BulkDelete

func (t *HTTPTransport[T]) BulkDelete(ctx context.Context, ids []string) error

func (*HTTPTransport[T]) BulkUpdate

func (t *HTTPTransport[T]) BulkUpdate(ctx context.Context, input *BulkUpdateInput[T]) (*BulkResponse[T], error)

func (*HTTPTransport[T]) Create

func (t *HTTPTransport[T]) Create(ctx context.Context, input *CreateInput[T]) (*ItemResponse[T], error)

func (*HTTPTransport[T]) Delete

func (t *HTTPTransport[T]) Delete(ctx context.Context, id string) error

func (*HTTPTransport[T]) Export

func (t *HTTPTransport[T]) Export(ctx context.Context, params ExportParams) ([]byte, error)

func (*HTTPTransport[T]) GetByID

func (t *HTTPTransport[T]) GetByID(ctx context.Context, id string) (*ItemResponse[T], error)

func (*HTTPTransport[T]) Import

func (t *HTTPTransport[T]) Import(ctx context.Context, data []byte, format string) (*ImportResponse, error)

func (*HTTPTransport[T]) List

func (t *HTTPTransport[T]) List(ctx context.Context, params *ListParams) (*ListResponse[T], error)

func (*HTTPTransport[T]) Name

func (t *HTTPTransport[T]) Name() string

func (*HTTPTransport[T]) PartialUpdate

func (t *HTTPTransport[T]) PartialUpdate(ctx context.Context, id string, input *PartialUpdateInput) (*ItemResponse[T], error)

func (*HTTPTransport[T]) Type

func (t *HTTPTransport[T]) Type() TransportType

func (*HTTPTransport[T]) Update

func (t *HTTPTransport[T]) Update(ctx context.Context, id string, input *UpdateInput[T]) (*ItemResponse[T], error)

type ImportResponse

type ImportResponse struct {
	Imported int      `json:"imported"`
	Failed   int      `json:"failed"`
	Errors   []string `json:"errors,omitempty"`
}

type ItemResponse

type ItemResponse[T any] struct {
	Data     T              `json:"data"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type ListMetadata

type ListMetadata struct {
	Page       int   `json:"page"`
	PageSize   int   `json:"page_size"`
	TotalCount int64 `json:"total_count"`
	TotalPages int   `json:"total_pages"`
}

type ListParams

type ListParams struct {
	Page           int      `json:"page,omitempty"`
	PageSize       int      `json:"page_size,omitempty"`
	Offset         int      `json:"offset,omitempty"`
	Search         string   `json:"search,omitempty"`
	Sort           string   `json:"sort,omitempty"`
	Order          string   `json:"order,omitempty"`
	Filter         *Filter  `json:"filter,omitempty"`
	Fields         []string `json:"fields,omitempty"`
	Embed          []string `json:"embed,omitempty"`
	IncludeDeleted bool     `json:"include_deleted,omitempty"`
}

type ListResponse

type ListResponse[T any] struct {
	Data     []T           `json:"data"`
	Metadata *ListMetadata `json:"metadata,omitempty"`
}

type Option

type Option func(*HTTPConfig)

func WithAPIKey

func WithAPIKey(apiKey string) Option

func WithBearerToken

func WithBearerToken(token string) Option

func WithHeader

func WithHeader(key, value string) Option

func WithQueryParam

func WithQueryParam(key, value string) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type PartialUpdateInput

type PartialUpdateInput struct {
	ID      string         `json:"id,omitempty"`
	Updates map[string]any `json:"updates"`
}

type Transport

type Transport interface {
	Type() TransportType
	Name() string
}

Transport is the base contract shared by all client transports.

type TransportType

type TransportType string

TransportType identifies a client transport implementation.

const (
	TransportTypeHTTP TransportType = "http"
)

type UpdateInput

type UpdateInput[T any] struct {
	ID   string `json:"id,omitempty"`
	Body T      `json:"body"`
}

Jump to

Keyboard shortcuts

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