client

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 9 Imported by: 0

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

func BuildHTTPRequest(baseURL string, req *Request) (*http.Request, error)

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).

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, req *Request) (*Response, error)

Execute sends the given Request, returns the parsed Response. Non-2xx status codes produce an *errors.AppError with the status and a brief message. On 401 it calls Auth.Login and retries once.

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.

type Response

type Response struct {
	Status int
	Body   []byte
	Header http.Header
}

Response wraps the raw HTTP response after it's been fully read.

Jump to

Keyboard shortcuts

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