serviceapi

package
v0.1.0-rc.41 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package serviceapi provides HTTP helpers for the service APIs.

Index

Constants

View Source
const MaximumRequestBytes = 64 << 10

Variables

This section is empty.

Functions

func AuthenticateClusterRequest

func AuthenticateClusterRequest(response http.ResponseWriter, request *http.Request, secrets BearerSecrets) bool

AuthenticateClusterRequest applies the private API's cache and authentication policy before dispatching a request to a role-specific router.

func DecodeJSON

func DecodeJSON(response http.ResponseWriter, request *http.Request, destination any) bool

func Nonnegative

func Nonnegative(value int64) (uint64, bool)

func Positive

func Positive(value int64) (uint64, bool)

func ValidIdentifiers

func ValidIdentifiers(values ...string) bool

func WriteJSON

func WriteJSON(response http.ResponseWriter, status int, value any)

func WriteProblem

func WriteProblem(response http.ResponseWriter, status int, problemType, detail string, caseID ...string)

func WriteProblemError

func WriteProblemError(response http.ResponseWriter, problem *ProblemError)

func WriteServiceError

func WriteServiceError(
	response http.ResponseWriter,
	request *http.Request,
	err error,
	report func(error),
	detail string,
) bool

WriteServiceError handles the shared private API error boundary. callers supply only the role-specific detail for unexpected failures.

Types

type BearerSecrets

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

BearerSecrets authenticates a current service secret and an optional previous secret retained only for a rolling rotation.

func NewBearerSecrets

func NewBearerSecrets(current, previous string) (BearerSecrets, error)

func (BearerSecrets) Authenticate

func (s BearerSecrets) Authenticate(header http.Header) bool

func (BearerSecrets) Matches

func (s BearerSecrets) Matches(candidate string) bool

func (BearerSecrets) Valid

func (s BearerSecrets) Valid() bool

type ProblemError

type ProblemError struct {
	Status    int
	Type      string
	Title     string
	Code      string
	Detail    string
	RequestID string
	CaseID    string
}

ProblemError describes a service API failure without HTTP client or server details.

func NewProblemError

func NewProblemError(status int, problemType, detail string) *ProblemError

func (*ProblemError) Error

func (e *ProblemError) Error() string

Jump to

Keyboard shortcuts

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