Documentation
¶
Overview ¶
Package serviceapi provides HTTP helpers for the service APIs.
Index ¶
- Constants
- func AuthenticateClusterRequest(response http.ResponseWriter, request *http.Request, secrets BearerSecrets) bool
- func DecodeJSON(response http.ResponseWriter, request *http.Request, destination any) bool
- func Nonnegative(value int64) (uint64, bool)
- func Positive(value int64) (uint64, bool)
- func ValidIdentifiers(values ...string) bool
- func WriteJSON(response http.ResponseWriter, status int, value any)
- func WriteProblem(response http.ResponseWriter, status int, problemType, detail string, ...)
- func WriteProblemError(response http.ResponseWriter, problem *ProblemError)
- func WriteServiceError(response http.ResponseWriter, request *http.Request, err error, ...) bool
- type BearerSecrets
- type ProblemError
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 Nonnegative ¶
func ValidIdentifiers ¶
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
Click to show internal directories.
Click to hide internal directories.