Documentation
¶
Overview ¶
Package client builds and executes HTTP requests for invgate-cli. The Executor attaches OAuth2 bearer tokens via the auth.Manager and auto-retries once on 401 by calling Login (which forces a fresh token) before re-executing the request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildHTTPRequest ¶
BuildHTTPRequest converts a Request into an *http.Request against the given base URL. It substitutes path placeholders with URL-encoded args, encodes query params, sets Content-Type, and writes the body. No Authorization header is added here — that's the executor's job.
Types ¶
type AuthManager ¶
type AuthManager interface {
Token(ctx context.Context) (string, error)
Login(ctx context.Context) error
}
Manager is the subset of auth.Manager required by the executor. We redeclare it locally to avoid an import cycle and keep the client package decoupled from the auth implementation.
type Executor ¶
type Executor struct {
BaseURL string
Auth AuthManager
HTTP *http.Client
Verbose bool
Logf func(format string, args ...any)
}
Executor runs HTTP requests against the API, attaching a bearer token fetched via the AuthManager. On 401 it forces a Login and retries once before surfacing the error.
func NewExecutor ¶
func NewExecutor(baseURL string, auth AuthManager, client *http.Client) *Executor
NewExecutor constructs an Executor with a default HTTP client if none is provided. The AuthManager may be nil for unauthenticated operations (e.g. health checks).
type Request ¶
type Request struct {
Method string
PathTemplate string
PathArgs []string
Query url.Values
Body []byte
ContentType string
}
Request is the high-level description of an API request, before auth and base URL are applied. PathTemplate uses {name} placeholders that get substituted by PathArgs in declaration order.