apicontract

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apicontract defines the release-independent Tapper REST contract.

Index

Constants

View Source
const ClientHeader = "Tapper-Client-Version"
View Source
const DefaultDiscoveryCacheTTL = time.Hour

DefaultDiscoveryCacheTTL is how long a cached discovery success is trusted when Session.CacheTTL is unset.

View Source
const DiscoveryInvalid = "API_DISCOVERY_INVALID"
View Source
const DiscoveryUnavailable = "API_DISCOVERY_UNAVAILABLE"
View Source
const Required = "API_VERSION_REQUIRED"
View Source
const Revision = "2026-10-17"

Revision is the contract this build speaks: the revision a client sends on every REST request and the newest one a Hub serves.

View Source
const Unsupported = "API_VERSION_UNSUPPORTED"
View Source
const VersionHeader = "Tapper-API-Version"

Variables

This section is empty.

Functions

func Do

func Do(client *http.Client, req *http.Request) (*http.Response, error)

Do applies discovery, mandatory headers, redirect restrictions and typed errors to a REST request. Non-REST OAuth and archive requests pass through unchanged.

func IsCompatibility

func IsCompatibility(err error) bool

func LogFailure

func LogFailure(ctx context.Context, logger *slog.Logger, level slog.Level, client string, err error, requestID string)

LogFailure emits only compatibility metadata, never request contents or credentials.

func Middleware

func Middleware(server string, logger *slog.Logger) func(http.Handler) http.Handler

Middleware gates all /api/v1 paths, including unknown operations, before auth. Discovery is build-only and remains usable when database services are down. An accepted request carries its revision in the response header and in its context (RequestRevision).

func RequestRevision added in v0.47.0

func RequestRevision(ctx context.Context) string

RequestRevision reports the contract revision Middleware accepted for the request carrying ctx, or "" when the request did not pass the REST gate.

func SupportedRevisions added in v0.47.0

func SupportedRevisions() []string

SupportedRevisions lists every revision a Hub accepts, newest first. The slice is a fresh copy on each call.

func WithRequestRevision added in v0.47.0

func WithRequestRevision(ctx context.Context, rev string) context.Context

WithRequestRevision returns ctx recording rev as the negotiated revision, as Middleware does for every accepted REST request. Tests of handlers that answer per revision use it to stand in for the gate.

func WithSession

func WithSession(ctx context.Context, s *Session) context.Context

Types

type CompatibilityError

type CompatibilityError struct {
	Message            string   `json:"error"`
	Code               string   `json:"code"`
	Requested          []string `json:"requested_api_versions"`
	Supported          []string `json:"supported_api_versions"`
	ServerVersion      string   `json:"server_version,omitempty"`
	OperationPerformed bool     `json:"operationPerformed"`
}

CompatibilityError guarantees the blocked application operation was not sent or was rejected by the server before authentication and dispatch.

func Validate

func Validate(h http.Header, server string) *CompatibilityError

Validate accepts exactly one unmodified contract revision header value naming one of SupportedRevisions.

func (*CompatibilityError) Error

func (e *CompatibilityError) Error() string

type Discovery

type Discovery struct {
	ServerVersion string   `json:"server_version"`
	APIVersions   []string `json:"api_versions"`
}

type DiscoveryCache added in v0.47.0

type DiscoveryCache interface {
	// Get returns when key last passed discovery.
	Get(key string) (time.Time, bool)
	// Put records that key passed discovery at checked.
	Put(key string, checked time.Time)
	// Delete forgets key after the Hub rejected the cached contract.
	Delete(key string)
}

DiscoveryCache persists successful discovery beyond one Session, so a new invocation can skip GET /api/version. Keys name a Hub base URL and this package's Revision. Only successes are stored; failures stay with the Session that saw them. Implementations must be safe for concurrent use and treat every error as a miss.

type Session

type Session struct {
	ClientVersion string
	Logger        *slog.Logger

	Cache    DiscoveryCache
	CacheTTL time.Duration
	Now      func() time.Time
	// contains filtered or unexported fields
}

Session caches discovery per Hub for one invocation or MCP connection.

Cache, when set, extends a success past the Session for CacheTTL (DefaultDiscoveryCacheTTL when zero), measured with Now (time.Now when nil). A stale entry is safe: the Hub still validates every request, and a typed rejection evicts the entry.

func FromContext

func FromContext(ctx context.Context) *Session

func NewSession

func NewSession(client string, logger *slog.Logger) *Session

func (*Session) Check

func (s *Session) Check(ctx context.Context, client *http.Client, base string) error

Check performs credential-free discovery once, bounded by the caller and five seconds.

Jump to

Keyboard shortcuts

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