http

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package http provides a TenantLister that pulls tenant IDs from a control-plane API conforming to the go-bricks pre-defined contract.

Contract (responses use the standard go-bricks APIResponse envelope):

GET <base>/tenants?limit=<int>&cursor=<opaque>
200 OK
{
  "data":  { "tenants": [ {"id": "..."}, ... ], "next_cursor": "..." },
  "meta":  { "timestamp": "...", "traceId": "..." }
}
4xx/5xx
{ "error": { "code": "...", "message": "..." }, "meta": { ... } }

next_cursor empty/absent ends the iteration.

Index

Constants

View Source
const DefaultPageLimit = 100

DefaultPageLimit is the default page size requested from the control-plane.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is applied to the underlying *http.Client when none is supplied.

Variables

View Source
var ErrInsecureScheme = errors.New("migration/source/http: http:// scheme requires Options.AllowInsecureScheme=true (defense-in-depth: bearer token would be transmitted in clear text)")

ErrInsecureScheme is returned by New when the supplied base URL uses a plaintext scheme (`http://`) and Options.AllowInsecureScheme is false.

View Source
var ErrUnsupportedScheme = errors.New("migration/source/http: unsupported URL scheme (expected http or https)")

ErrUnsupportedScheme is returned by New when the supplied base URL uses a scheme other than http or https.

Functions

This section is empty.

Types

type ContractError

type ContractError struct {
	StatusCode int
	Code       string
	Message    string
}

ContractError is returned when the control-plane responds with a non-2xx status. It exposes the envelope's error fields for diagnostics.

func (*ContractError) Error

func (e *ContractError) Error() string

type Options

type Options struct {
	// BearerToken is sent in the Authorization header when non-empty.
	BearerToken string

	// Client overrides the default HTTP client. When nil, a client with a
	// DefaultTimeout is used.
	Client *stdhttp.Client

	// PageLimit is sent as the ?limit= query parameter on each request.
	// Servers may cap this. When 0 or negative, DefaultPageLimit is used.
	PageLimit int

	// AllowInsecureScheme opts in to accepting `http://` base URLs. By default
	// New() rejects plaintext schemes so an operator-supplied bearer token is
	// never transmitted in clear text. Set this to true only for LocalStack,
	// dev loops, or internal-only tooling on private networks.
	AllowInsecureScheme bool
}

Options configures TenantSource.

type TenantSource

type TenantSource struct {
	// contains filtered or unexported fields
}

TenantSource implements migration.TenantLister against an HTTP control-plane API.

func New

func New(baseURL string, opts Options) (*TenantSource, error)

New constructs a TenantSource. baseURL must be parseable; the /tenants path is appended automatically. Plaintext `http://` URLs are rejected unless opts.AllowInsecureScheme is true (defense-in-depth around the bearer token).

func (*TenantSource) ListTenants

func (s *TenantSource) ListTenants(ctx context.Context) ([]string, error)

ListTenants walks all pages of the contract endpoint and returns the union of tenant IDs.

Jump to

Keyboard shortcuts

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