Documentation
¶
Overview ¶
Code generated by apic; DO NOT EDIT.
Code generated by apic; DO NOT EDIT.
Code generated by apic; DO NOT EDIT.
Code generated by apic; DO NOT EDIT.
Index ¶
- Constants
- Variables
- func CheckSpecHash(resp *http.Response) error
- func WithCorrelationID(ctx context.Context, id string) context.Context
- func WithTraceParent(ctx context.Context, traceparent string) context.Context
- type BinarySocket
- type Client
- func (c *Client) ConnectBinary(ctx context.Context) (*BinarySocket, error)
- func (c *Client) ConnectFeed(ctx context.Context) (*JSONSocket[types.FeedMsg], error)
- func (c *Client) Create(ctx context.Context, req *types.PostCreateReq) (*types.PostCreateResp, error)
- func (c *Client) GraphQLCreatePost(ctx context.Context, req *types.PostCreateReq) (*types.PostCreateResp, error)
- func (c *Client) GraphQLRegisterUser(ctx context.Context, req *types.RegisterReq) (*types.RegisterResp, error)
- func (c *Client) GraphQLSearchPosts(ctx context.Context, req *types.PostSearchReq) (*types.PostSearchResp, error)
- func (c *Client) GraphQLSubscribeBinaryStream(ctx context.Context) (*GraphQLSubscription[types.BinaryMsg], error)
- func (c *Client) GraphQLSubscribeFeedEvents(ctx context.Context) (*GraphQLSubscription[types.FeedMsg], error)
- func (c *Client) GraphQLUpdateUser(ctx context.Context, req *types.UserUpdateReq) (*types.UserUpdateResp, error)
- func (c *Client) Register(ctx context.Context, req *types.RegisterReq) (*types.RegisterResp, error)
- func (c *Client) Search(ctx context.Context, req *types.PostSearchReq) (*types.PostSearchResp, error)
- func (c *Client) Update(ctx context.Context, req *types.UserUpdateReq) (*types.UserUpdateResp, error)
- type ClientOption
- func WithAPIKeySecret(secret []byte) ClientOption
- func WithBearerToken(token string) ClientOption
- func WithHTTPClient(client *http.Client) ClientOption
- func WithRequestEditor(fn RequestEditorFn) ClientOption
- func WithWSHeaders(headers http.Header) ClientOption
- func WithWSOrigin(origin string) ClientOption
- func WithoutTracePropagation() ClientOption
- type GraphQLSubscription
- type HTTPError
- type JSONSocket
- type RequestEditorFn
- type SpecMismatchError
Constants ¶
const APISpecHash = "d1416053a177f710a7b57be5968d2e0a2afebacfb455bfff164c9cbc298b9f03"
APISpecHash is the deterministic identity of the spec this client was generated from: the SHA-256, in lowercase hex, of a canonical (member-order independent) encoding of the resolved config's public contract (the sanitized /api-spec.json document, minus client/shared toggles). The generated server stamps the identical value on every response as the SpecHashHeader header and publishes it as the "x-apic-spec-hash" member of /api-spec.json, so an unequal value means client and server were generated from different spec revisions.
const SpecHashHeader = "X-Apic-Spec-Hash"
SpecHashHeader is the response header the generated server advertises its spec hash on. Operators may suppress the header with server.spec_hash_header:false, in which case CheckSpecHash reports no mismatch (there is nothing to compare against).
Variables ¶
var ( // ErrMissingAPIKeySecret indicates api_key auth was required but no secret was configured. ErrMissingAPIKeySecret = errors.New("missing API key secret") // ErrMissingBearerToken indicates jwt auth was required but no bearer token was configured. ErrMissingBearerToken = errors.New("missing bearer token") )
var ErrSpecMismatch = errors.New("apic: client/server spec hash mismatch")
ErrSpecMismatch is returned (wrapped in a *SpecMismatchError) when the server advertises a spec hash that differs from APISpecHash. It is deliberately a NON-fatal signal: the client does not refuse the response, and CheckSpecHash is opt-in -- nothing in the generated request path calls it. Match it with errors.Is to warn, log, or trigger a regeneration.
Functions ¶
func CheckSpecHash ¶ added in v0.18.3
CheckSpecHash compares the spec hash the server advertised on resp against this client's embedded APISpecHash. It is an opt-in, non-fatal diagnostic: call it on any response (typically once, after the first successful call) to detect that the client was generated from a different spec revision than the server is serving.
It returns nil when the hashes match, when the server sent no SpecHashHeader header (an older server, or one with server.spec_hash_header:false), and when resp is nil. It returns a *SpecMismatchError -- which satisfies errors.Is(err, ErrSpecMismatch) -- only when both values are present and differ.
func WithCorrelationID ¶ added in v0.15.0
WithCorrelationID attaches an end-to-end correlation id to ctx. The client sends it as the defaultCorrelationHeader ("X-Correlation-ID") header on every REST, GraphQL, and WebSocket call. When ctx carries none (or an unusable value), the client generates one per call.
func WithTraceParent ¶ added in v0.15.0
WithTraceParent attaches a W3C traceparent to ctx for explicit trace-context passthrough. When well-formed ("00-<32-hex trace-id>-<16-hex span-id>-<2-hex flags>") the client forwards it verbatim as the "traceparent" header on every REST, GraphQL, and WebSocket call. The client links no OpenTelemetry runtime, so it never derives a traceparent from an ambient span — pass it explicitly.
Types ¶
type BinarySocket ¶
type BinarySocket struct {
// contains filtered or unexported fields
}
BinarySocket wraps a binary WebSocket endpoint.
func (*BinarySocket) Close ¶
func (s *BinarySocket) Close() error
Close closes the underlying websocket.
func (*BinarySocket) Receive ¶
func (s *BinarySocket) Receive() ([]byte, error)
Receive blocks until the next binary payload arrives.
func (*BinarySocket) Send ¶
func (s *BinarySocket) Send(payload []byte) error
Send writes one binary payload.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the generated Go client for REST, GraphQL, and WebSocket APIs.
func New ¶
func New(baseURL string, opts ...ClientOption) (*Client, error)
New constructs a generated client from an absolute base URL.
func (*Client) ConnectBinary ¶
func (c *Client) ConnectBinary(ctx context.Context) (*BinarySocket, error)
ConnectBinary opens /ws/binary.
func (*Client) ConnectFeed ¶
ConnectFeed opens /ws/feed.
func (*Client) Create ¶
func (c *Client) Create(ctx context.Context, req *types.PostCreateReq) (*types.PostCreateResp, error)
Create performs POST /v1/posts/create.
func (*Client) GraphQLCreatePost ¶
func (c *Client) GraphQLCreatePost(ctx context.Context, req *types.PostCreateReq) (*types.PostCreateResp, error)
GraphQLCreatePost performs the createPost GraphQL mutation.
func (*Client) GraphQLRegisterUser ¶
func (c *Client) GraphQLRegisterUser(ctx context.Context, req *types.RegisterReq) (*types.RegisterResp, error)
GraphQLRegisterUser performs the registerUser GraphQL mutation.
func (*Client) GraphQLSearchPosts ¶
func (c *Client) GraphQLSearchPosts(ctx context.Context, req *types.PostSearchReq) (*types.PostSearchResp, error)
GraphQLSearchPosts performs the searchPosts GraphQL mutation.
func (*Client) GraphQLSubscribeBinaryStream ¶
func (c *Client) GraphQLSubscribeBinaryStream(ctx context.Context) (*GraphQLSubscription[types.BinaryMsg], error)
GraphQLSubscribeBinaryStream opens a typed GraphQL subscription stream.
func (*Client) GraphQLSubscribeFeedEvents ¶
func (c *Client) GraphQLSubscribeFeedEvents(ctx context.Context) (*GraphQLSubscription[types.FeedMsg], error)
GraphQLSubscribeFeedEvents opens a typed GraphQL subscription stream.
func (*Client) GraphQLUpdateUser ¶
func (c *Client) GraphQLUpdateUser(ctx context.Context, req *types.UserUpdateReq) (*types.UserUpdateResp, error)
GraphQLUpdateUser performs the updateUser GraphQL mutation.
func (*Client) Register ¶
func (c *Client) Register(ctx context.Context, req *types.RegisterReq) (*types.RegisterResp, error)
Register performs POST /v1/users/register.
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, req *types.PostSearchReq) (*types.PostSearchResp, error)
Search performs POST /v1/posts/search.
func (*Client) Update ¶
func (c *Client) Update(ctx context.Context, req *types.UserUpdateReq) (*types.UserUpdateResp, error)
Update performs POST /v1/users/update.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption mutates a generated client.
func WithAPIKeySecret ¶
func WithAPIKeySecret(secret []byte) ClientOption
WithAPIKeySecret configures the HMAC secret used by api_key endpoints.
func WithBearerToken ¶
func WithBearerToken(token string) ClientOption
WithBearerToken configures the JWT bearer token used by jwt-protected endpoints.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient overrides the HTTP transport.
func WithRequestEditor ¶
func WithRequestEditor(fn RequestEditorFn) ClientOption
WithRequestEditor appends a request editor.
func WithWSHeaders ¶
func WithWSHeaders(headers http.Header) ClientOption
WithWSHeaders configures extra headers for outbound WebSocket handshakes.
func WithWSOrigin ¶
func WithWSOrigin(origin string) ClientOption
WithWSOrigin sets the Origin header for outbound WebSocket handshakes.
func WithoutTracePropagation ¶ added in v0.15.0
func WithoutTracePropagation() ClientOption
WithoutTracePropagation disables automatic correlation-id and traceparent header injection on outbound REST, GraphQL, and WebSocket calls. Injection is on by default; a request editor set via WithRequestEditor can still add or override these headers regardless of this option.
type GraphQLSubscription ¶
type GraphQLSubscription[T any] struct { // contains filtered or unexported fields }
GraphQLSubscription streams typed messages from a graphql-transport-ws subscription.
func (*GraphQLSubscription[T]) Close ¶
func (s *GraphQLSubscription[T]) Close() error
Close terminates the subscription and underlying websocket.
func (*GraphQLSubscription[T]) Next ¶
func (s *GraphQLSubscription[T]) Next() (T, error)
Next blocks until the next payload, completion, or error.
type JSONSocket ¶
type JSONSocket[T any] struct { // contains filtered or unexported fields }
JSONSocket wraps a typed JSON WebSocket endpoint.
func (*JSONSocket[T]) Close ¶
func (s *JSONSocket[T]) Close() error
Close closes the underlying websocket.
func (*JSONSocket[T]) Receive ¶
func (s *JSONSocket[T]) Receive() (T, error)
Receive blocks until the next JSON message arrives.
func (*JSONSocket[T]) Send ¶
func (s *JSONSocket[T]) Send(msg T) error
Send writes one JSON message.
type RequestEditorFn ¶
RequestEditorFn mutates outbound REST and GraphQL HTTP requests before auth is applied.
type SpecMismatchError ¶ added in v0.18.3
type SpecMismatchError struct {
// Client is this client's embedded APISpecHash.
Client string
// Server is the value the server advertised in the SpecHashHeader header.
Server string
}
SpecMismatchError carries both sides of a spec-hash mismatch so a caller can report exactly which revisions disagree.
func (*SpecMismatchError) Error ¶ added in v0.18.3
func (e *SpecMismatchError) Error() string
func (*SpecMismatchError) Unwrap ¶ added in v0.18.3
func (e *SpecMismatchError) Unwrap() error
Unwrap makes errors.Is(err, ErrSpecMismatch) report true.