Documentation
¶
Index ¶
- func InferKind[M any]() string
- type Authorization
- type BearerTokenAuthorization
- type ExponentialBackoff
- type HttpClient
- type HttpError
- type Logger
- type MeshInfo
- type MeshObjectClient
- func (c MeshObjectClient[M]) Delete(ctx context.Context, id string) (err error)
- func (c MeshObjectClient[M]) Get(ctx context.Context, id string) (resp *M, err error)
- func (c MeshObjectClient[M]) List(ctx context.Context, options ...RequestOption) ([]M, error)
- func (c MeshObjectClient[M]) Post(ctx context.Context, payload any) (*M, error)
- func (c MeshObjectClient[M]) Purge(ctx context.Context, id string) (err error)
- func (c MeshObjectClient[M]) Put(ctx context.Context, id string, payload any) (*M, error)
- type RequestOption
- type RetryBackoff
- type RetryOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
func (auth BearerTokenAuthorization) Header(_ context.Context, _ HttpClient) (string, error)
type ExponentialBackoff ¶ added in v0.20.7
ExponentialBackoff increases the backoff exponentially: minWait * 2^(attempt-1).
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
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) IsForbidden ¶ added in v0.20.6
IsForbidden returns true if the error is a 403 Forbidden response.
func (HttpError) IsNotFound ¶ added in v0.20.6
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 MeshObjectClient ¶
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.
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
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.