Documentation
¶
Overview ¶
Package httpclient provides a generic HTTP client for protosource aggregates with protobuf-first content negotiation.
Index ¶
- type APIError
- type AuthProvider
- type BearerTokenAuth
- type Client
- func (c *Client) Apply(ctx context.Context, routePath string, cmd proto.Message) (responsev1.Responseer, error)
- func (c *Client) Get(ctx context.Context, routePath string, id string, target proto.Message) error
- func (c *Client) History(ctx context.Context, routePath string, id string) (*historyv1.History, error)
- func (c *Client) Load(ctx context.Context, routePath string, id string, target proto.Message) error
- func (c *Client) Query(ctx context.Context, routePath string, queryPath string, ...) error
- type Doer
- type NoAuth
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int `json:"-"`
Code string `json:"code"`
Message string `json:"error"`
Detail string `json:"detail,omitempty"`
}
APIError represents an error response from the server. The server sends {"code": "...", "error": "...", "detail": "..."}.
type AuthProvider ¶
AuthProvider decorates outgoing HTTP requests with authentication. Implementations can add bearer tokens, API keys, signed headers, etc. Also provides the actor identity for command attribution.
type BearerTokenAuth ¶
type BearerTokenAuth struct {
// contains filtered or unexported fields
}
BearerTokenAuth adds a Bearer token to each request.
func NewBearerTokenAuth ¶
func NewBearerTokenAuth(token, actor string) *BearerTokenAuth
NewBearerTokenAuth creates an AuthProvider that sets Authorization: Bearer.
func (*BearerTokenAuth) Actor ¶
func (a *BearerTokenAuth) Actor() string
func (*BearerTokenAuth) Authenticate ¶
func (a *BearerTokenAuth) Authenticate(req *http.Request) error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a generic protosource HTTP client with content negotiation.
func New ¶
func New(baseURL string, auth AuthProvider, opts ...Option) *Client
New creates a new Client. Panics if auth is nil.
func (*Client) Apply ¶
func (c *Client) Apply(ctx context.Context, routePath string, cmd proto.Message) (responsev1.Responseer, error)
Apply sends a command to the server and returns the result. The actor field is set from the AuthProvider before serialization.
func (*Client) History ¶
func (c *Client) History(ctx context.Context, routePath string, id string) (*historyv1.History, error)
History retrieves the event history for an aggregate.
func (*Client) Load ¶
Load retrieves an aggregate by ID via event replay, unmarshaling into the provided message.
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, routePath string, queryPath string, params map[string]string, target proto.Message) error
Query sends a GET request to a query endpoint and unmarshals the response into the target proto.Message (typically an {Aggregate}List). The queryPath is appended to {baseURL}/{routePath}/query/{queryPath}. Params are sent as URL query parameters.
type Doer ¶
type Doer interface {
Apply(ctx context.Context, routePath string, cmd proto.Message) (responsev1.Responseer, error)
Load(ctx context.Context, routePath string, id string, target proto.Message) error
Get(ctx context.Context, routePath string, id string, target proto.Message) error
History(ctx context.Context, routePath string, id string) (*historyv1.History, error)
Query(ctx context.Context, routePath string, queryPath string, params map[string]string, target proto.Message) error
}
Doer is the interface that generated per-aggregate clients depend on. *Client satisfies it. Consumers can mock this for testing.