internal

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferKind added in v0.20.4

func InferKind[M any]() string

InferKind infers the meshObject kind from a struct type name using the same convention as the meshObject API: MeshWorkspace → "meshWorkspace", MeshTenantV4 → "meshTenant". Version suffixes (V\d+) are stripped. Tested when client.Kind is statically initialized.

Types

type Authorization added in v0.20.7

type Authorization interface {
	Header(ctx context.Context, client HttpClient) (string, error)
}

func NewClientSecretAuthorization added in v0.20.7

func NewClientSecretAuthorization(loginApiPath, clientId, clientSecret string) Authorization

type BearerTokenAuthorization added in v0.20.7

type BearerTokenAuthorization struct {
	Token string
}

func (BearerTokenAuthorization) Header added in v0.20.7

type ExponentialBackoff added in v0.20.7

type ExponentialBackoff struct {
	MinWait, MaxWait time.Duration
}

ExponentialBackoff increases the backoff exponentially: minWait * 2^(attempt-1).

func (ExponentialBackoff) Calculate added in v0.20.7

func (b ExponentialBackoff) Calculate(attempt int) time.Duration

type HttpClient

type HttpClient struct {
	*http.Client
	RootUrl       *url.URL
	UserAgent     string
	Authorization Authorization
}

HttpClient wraps http.Client with convenient request handling thanks to RequestOption.

func NewHttpClient added in v0.20.7

func NewHttpClient(rootUrl *url.URL, userAgent string, auth Authorization) HttpClient

NewHttpClient creates a new client with an underlying http.Client being a pointer to be modified by WithRetry.

func WithRetry added in v0.20.7

func WithRetry(c HttpClient, options RetryOptions) HttpClient

WithRetry sets up the given client to retry certain requests. GET and PUT are retried by default, POST only if the path is explicitly whitelisted. See RetryOptions.

func (HttpClient) GetMeshInfo

func (c HttpClient) GetMeshInfo(ctx context.Context) (*MeshInfo, error)

type HttpError added in v0.20.6

type HttpError struct {
	StatusCode   int
	ResponseBody []byte
}

HttpError represents an HTTP error response with status code. This error is returned when an HTTP request fails with a non-2XX status code.

func (HttpError) Error added in v0.20.6

func (e HttpError) Error() string

func (HttpError) IsForbidden added in v0.20.6

func (e HttpError) IsForbidden() bool

IsForbidden returns true if the error is a 403 Forbidden response.

func (HttpError) IsNotFound added in v0.20.6

func (e HttpError) IsNotFound() bool

IsNotFound returns true if the error is a 404 Not Found response.

type Logger

type Logger interface {
	Debug(ctx context.Context, msg string, args ...any)
	Info(ctx context.Context, msg string, args ...any)
	Warn(ctx context.Context, msg string, args ...any)
}

Logger supports Debug, Info, and Warn log levels. Note that msg is a short, descriptive statement what is logged, and args are key value pairs (values are string or implement fmt.Stringer).

var Log Logger = noopLogger{}

type MeshInfo

type MeshInfo struct {
	Version version.Version `json:"version"`
}

type MeshObjectClient

type MeshObjectClient[M any] struct {
	HttpClient
	Kind       string
	ApiVersion string
	ApiUrl     *url.URL
}

MeshObjectClient provides typed CRUD operations for meshStack API objects. It embeds HttpClient and adds meshObject-specific functionality including automatic MIME type handling and pagination. Also handles authentication in doAuthorizedRequest using the ApiKey/ApiSecret values, which are embedded in HttpClient for convenient construction with NewMeshObjectClient.

func NewMeshObjectClient

func NewMeshObjectClient[M any](ctx context.Context, httpClient HttpClient, apiVersion string, explicitApiPathElems ...string) MeshObjectClient[M]

NewMeshObjectClient creates a new MeshObjectClient for a specific meshObject type with automatic URL path inference. The meshObject kind is inferred from type M. T The API URL is constructed from explicitApiPathElems if provided, otherwise the pluralized and lowercased kind is used as a single element.

func (MeshObjectClient[M]) Delete

func (c MeshObjectClient[M]) Delete(ctx context.Context, id string) (err error)

Delete removes a meshObject by ID.

func (MeshObjectClient[M]) Get

func (c MeshObjectClient[M]) Get(ctx context.Context, id string) (resp *M, err error)

Get retrieves a meshObject by ID. Returns nil if not found.

func (MeshObjectClient[M]) List

func (c MeshObjectClient[M]) List(ctx context.Context, options ...RequestOption) ([]M, error)

List retrieves all meshObjects with automatic pagination handling. Accepts optional RequestOption parameters for filtering and querying.

func (MeshObjectClient[M]) Post

func (c MeshObjectClient[M]) Post(ctx context.Context, payload any) (*M, error)

Post creates a new meshObject with the given payload. Automatically injects apiVersion and kind into the JSON payload.

func (MeshObjectClient[M]) Purge added in v0.21.0

func (c MeshObjectClient[M]) Purge(ctx context.Context, id string) (err error)

Purge removes a meshObject by ID without running any cloud-side cleanup, by calling DELETE /{id}/purge.

func (MeshObjectClient[M]) Put

func (c MeshObjectClient[M]) Put(ctx context.Context, id string, payload any) (*M, error)

Put updates an existing meshObject by ID with the given payload. Automatically injects apiVersion and kind into the JSON payload.

type RequestOption

type RequestOption func(opts *requestOptions)

RequestOption is a functional option for configuring HTTP requests.

func WithUrlQuery

func WithUrlQuery(key string, value any) RequestOption

WithUrlQuery adds a URL query parameter to the request. The value is stringified using fmt.Stringer.String() if implemented, otherwise fmt.Sprintf("%v", value).

type RetryBackoff added in v0.20.7

type RetryBackoff interface {
	Calculate(attempt int) time.Duration
}

RetryBackoff calculates the duration to wait before the next retry attempt.

type RetryOptions added in v0.20.7

type RetryOptions struct {
	// MaxRetries limits the attempts to retries. If zero, retries will never be attempted.
	MaxRetries int
	// Backoff to use when retrying. If nil, retries will never be attempted.
	Backoff RetryBackoff
	// WhitelistedPaths allow methods beyond GET and PUT to be retried as well, see WithRetry.
	WhitelistedPaths map[string][]string
}

RetryOptions configure WithRetry.

Jump to

Keyboard shortcuts

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