Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package client provides typed administrative HTTP access. New selects one borrowed authentication source, copies HTTP settings with redirects disabled, and bounds buffered response bytes. The caller owns transport/TLS trust, credential lifetime and collaborator blocking/concurrency; no polling or shutdown goroutine is started. Ordinary successful JSON models are decoded, not universally semantically validated; GetDesiredState adds exact-target validation for worker convergence.

Index

Examples

Constants

View Source
const (
	// APIKeyIDHeader carries the non-secret static key identifier accepted by
	// the deployable control-plane server.
	// #nosec G101 -- public HTTP header name, not a credential; credential values come from caller-owned authentication
	APIKeyIDHeader = "X-Queue-Control-Key-ID"
	// APIKeySecretHeader carries the static key credential accepted by the
	// deployable control-plane server.
	// #nosec G101 -- public HTTP header name, not a credential; credential values come from caller-owned authentication
	APIKeySecretHeader = "X-Queue-Control-Key"
)

Variables

View Source
var (
	// ErrInvalidConfiguration reports an invalid endpoint, authentication
	// choice or response bound.
	ErrInvalidConfiguration = errors.New("control-plane client: invalid configuration")
	// ErrInvalidRequest reports unsupported or unbounded typed request input.
	ErrInvalidRequest = errors.New("control-plane client: invalid request")
	// ErrInvalidToken reports a blank token returned by the borrowed token
	// source.
	ErrInvalidToken = errors.New("control-plane client: invalid bearer token")
	// ErrInvalidAPIKey reports a blank key identifier or secret returned by the
	// borrowed key source.
	ErrInvalidAPIKey = errors.New("control-plane client: invalid API key")
	// ErrResponseTooLarge reports a response exceeding the configured byte
	// bound before JSON decoding.
	ErrResponseTooLarge = errors.New("control-plane client: response too large")
)
View Source
var ErrInvalidResponse = errors.New("control-plane client: invalid response")

ErrInvalidResponse reports malformed or mismatched successful API output.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// Status is the non-success HTTP status returned by the remote server.
	Status int
	// Code is decoded from the remote problem body and printed by Error; it is
	// not independently sanitized by Client.
	Code string
}

APIError is a stable non-success administrative response.

func (*APIError) Error

func (e *APIError) Error() string

Error prints status and server-provided Code, not the entire response body.

type APIKeySource

type APIKeySource interface {
	// APIKey returns a nonblank identifier and secret for this request;
	// implementations own blocking, concurrency and secret lifetime.
	APIKey(context.Context) (string, string, error)
}

APIKeySource acquires a static API-key identifier and secret for one request context.

type AuditQuery

type AuditQuery struct {
	// After is the exclusive audit sequence cursor; zero starts at retained
	// history.
	After uint64
	// Limit bounds one audit page; zero leaves the server default.
	Limit uint32
}

AuditQuery contains bounded audit-history pagination.

type Client

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

Client calls the versioned administrative API after New; its zero value is invalid. Shared use requires safe borrowed transports and credential sources. Methods close response bodies but do not close the transport or credentials.

func New

func New(config Config) (*Client, error)

New creates a typed administrative API client.

func (*Client) DesiredStateReader

func (c *Client) DesiredStateReader(tenant string) (queue.DesiredStateReader, error)

DesiredStateReader binds one tenant for use by a queue reconciler.

Example

ExampleClient_DesiredStateReader composes one caller-scheduled reconciliation against an owned synthetic HTTP server; it does not start a polling loop or prove production authentication, queue delivery or durability.

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"net/http"
	"net/http/httptest"
	"time"

	"github.com/faustbrian/go-queue-control-plane/v4/client"
	queue "github.com/faustbrian/go-queue/management"
)

// ExampleClient_DesiredStateReader composes one caller-scheduled reconciliation
// against an owned synthetic HTTP server; it does not start a polling loop or
// prove production authentication, queue delivery or durability.
func main() {
	target := queue.Target{Kind: queue.TargetQueue, Name: "critical"}
	server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
		_ = json.NewEncoder(writer).Encode(queue.DesiredRecord{
			Target: target, State: queue.DesiredPaused, Revision: 3,
			ChangedAt: time.Date(2026, 7, 16, 10, 0, 0, 0, time.UTC),
			CommandID: "pause-critical-3",
		})
	}))
	defer server.Close()

	api, err := client.New(client.Config{
		BaseURL: server.URL,
		APIKeys: exampleAPIKeySource{},
	})
	if err != nil {
		panic(err)
	}
	reader, err := api.DesiredStateReader("tenant-1")
	if err != nil {
		panic(err)
	}
	reconciler, err := queue.NewDesiredStateReconciler(
		queue.DesiredStateReconcilerConfig{
			Reader: reader, Applier: exampleDesiredApplier{},
			Targets: []queue.Target{target},
		},
	)
	if err != nil {
		panic(err)
	}
	if err := reconciler.Reconcile(context.Background()); err != nil {
		panic(err)
	}
}

type exampleAPIKeySource struct{}

func (exampleAPIKeySource) APIKey(context.Context) (string, string, error) {
	return "worker-1", "example-secret", nil
}

type exampleDesiredApplier struct{}

func (exampleDesiredApplier) ApplyDesiredState(
	_ context.Context,
	record queue.DesiredRecord,
) error {
	fmt.Printf(
		"apply %s to %s at revision %d\n",
		record.State,
		record.Target.Name,
		record.Revision,
	)
	return nil
}
Output:
apply paused to critical at revision 3

func (*Client) ExecuteCommand

func (c *Client) ExecuteCommand(
	ctx context.Context,
	tenant string,
	command apihttp.CommandRequest,
) (controlplane.CommandResult, error)

ExecuteCommand submits one actor-free command request for a tenant.

func (*Client) GetCommand

func (c *Client) GetCommand(
	ctx context.Context,
	tenant string,
	key string,
) (controlplane.CommandResult, error)

GetCommand returns one tenant-scoped durable command outcome.

func (*Client) GetDesiredState

func (c *Client) GetDesiredState(
	ctx context.Context,
	tenant string,
	target queue.Target,
) (queue.DesiredRecord, error)

GetDesiredState returns one validated tenant-scoped convergence record.

func (*Client) InspectDeadLetter

func (c *Client) InspectDeadLetter(
	ctx context.Context,
	tenant string,
	id string,
	visibility queue.PayloadVisibility,
) (apihttp.Record, error)

InspectDeadLetter returns one tenant dead letter at the requested visibility.

func (*Client) InspectDeadLetterWithOptions

func (c *Client) InspectDeadLetterWithOptions(
	ctx context.Context,
	tenant string,
	id string,
	options RecordInspectOptions,
) (apihttp.Record, error)

InspectDeadLetterWithOptions returns a dead letter with explicit privileged fields.

func (*Client) InspectFailure

func (c *Client) InspectFailure(
	ctx context.Context,
	tenant string,
	id string,
	visibility queue.PayloadVisibility,
) (apihttp.Record, error)

InspectFailure returns one tenant failure at the requested visibility.

func (*Client) InspectFailureWithOptions

func (c *Client) InspectFailureWithOptions(
	ctx context.Context,
	tenant string,
	id string,
	options RecordInspectOptions,
) (apihttp.Record, error)

InspectFailureWithOptions returns a failure with explicit privileged fields.

func (*Client) ListAudit

func (c *Client) ListAudit(
	ctx context.Context,
	tenant string,
	query AuditQuery,
) (apihttp.AuditPage, error)

ListAudit returns one bounded tenant audit-history page.

func (*Client) ListCommands

func (c *Client) ListCommands(
	ctx context.Context,
	tenant string,
	query CommandQuery,
) (apihttp.CommandHistoryPage, error)

ListCommands returns one bounded tenant command-history page.

func (*Client) ListDeadLetters

func (c *Client) ListDeadLetters(
	ctx context.Context,
	tenant string,
	query RecordQuery,
) (apihttp.RecordPage, error)

ListDeadLetters returns one bounded tenant dead-letter page.

func (*Client) ListFailures

func (c *Client) ListFailures(
	ctx context.Context,
	tenant string,
	query RecordQuery,
) (apihttp.RecordPage, error)

ListFailures returns one bounded tenant failure page.

func (*Client) ListQueues

func (c *Client) ListQueues(
	ctx context.Context,
	tenant string,
	query QueueQuery,
) (apihttp.QueuePage, error)

ListQueues returns one bounded tenant queue-status page.

func (*Client) ListWorkers

func (c *Client) ListWorkers(
	ctx context.Context,
	tenant string,
	query WorkerQuery,
) (apihttp.WorkerPage, error)

ListWorkers returns one bounded tenant worker page.

func (*Client) ListWorkloads

func (c *Client) ListWorkloads(
	ctx context.Context,
	tenant string,
	query WorkloadQuery,
) (controlkubernetes.Page, error)

ListWorkloads returns one bounded tenant workload page.

type CommandQuery

type CommandQuery struct {
	// Cursor is optional bounded opaque newest-first pagination state.
	Cursor string
	// Limit bounds one command page; zero leaves the server default.
	Limit uint32
}

CommandQuery contains bounded command-history pagination.

type Config

type Config struct {
	// BaseURL must be an HTTP(S) origin without credentials, query, fragment or
	// non-root path; TLS trust is caller-configured.
	BaseURL string
	// HTTPClient is shallow-copied with redirects disabled; nil selects a
	// 30-second client. Transport and Jar remain shared caller-owned
	// collaborators.
	HTTPClient *http.Client
	// Tokens is one borrowed authentication source; exactly one of Tokens and
	// APIKeys must be supplied.
	Tokens TokenSource
	// APIKeys is one borrowed authentication source, mutually exclusive with
	// Tokens.
	APIKeys APIKeySource
	// MaxResponseBytes bounds buffered response bytes before JSON parsing; zero
	// selects 4 MiB, negative values fail.
	MaxResponseBytes int64
}

Config defines the API endpoint, authentication, and response bounds.

type QueueQuery

type QueueQuery struct {
	// Cursor is optional bounded backend pagination state, not authorization.
	Cursor string
	// Limit bounds one queue-status page; zero leaves the server default.
	Limit uint32
}

QueueQuery contains bounded queue-status pagination.

type RecordInspectOptions

type RecordInspectOptions struct {
	// Payload must select hidden, redacted or revealed visibility. Revealed
	// bytes require additional permission/access audit; hidden/redacted
	// inspection still requires record_inspect.
	Payload queue.PayloadVisibility
	// RevealDiagnostics requests separately authorized/audited diagnostics, not
	// blanket payload access.
	RevealDiagnostics bool
}

RecordInspectOptions controls independently privileged record fields.

type RecordQuery

type RecordQuery struct {
	// Cursor is optional bounded backend pagination state.
	Cursor string
	// Limit bounds one record page; zero leaves the server default.
	Limit uint32
	// Search is optional bounded metadata search text; it is not payload
	// search.
	Search string
	// Sort optionally selects occurrence time, queue or attempt ordering.
	Sort queue.SortField
	// Direction optionally selects ascending or descending order; empty leaves
	// the server default.
	Direction queue.SortDirection
}

RecordQuery contains bounded failure and dead-letter list controls.

type TokenSource

type TokenSource interface {
	// Token acquires credentials synchronously for ctx; callers own blocking,
	// shared-use safety and credential lifetime.
	Token(context.Context) (string, error)
}

TokenSource acquires a bearer token for one request context.

type WorkerQuery

type WorkerQuery struct {
	// Limit bounds one worker page; zero leaves the server default and values
	// above MaxWorkerPageSize fail.
	Limit uint32
	// After is the optional last worker identity cursor passed to the server.
	After string
	// State optionally filters derived fleet state; the server validates
	// supported values.
	State fleet.State
	// Queue optionally selects a queue membership filter.
	Queue string
}

WorkerQuery contains bounded worker-list filters.

type WorkloadQuery

type WorkloadQuery struct {
	// Limit bounds one workload page; zero leaves the server default, negative
	// or oversized values fail.
	Limit int64
	// Continue is the optional opaque Kubernetes pagination token, not an
	// authorization capability.
	Continue string
}

WorkloadQuery contains bounded Kubernetes pagination.

Jump to

Keyboard shortcuts

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