apiframework

package
v0.0.51 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEncodeInvalidJSON      = errors.New("serverops: encoding failing, invalid json")
	ErrDecodeInvalidJSON      = errors.New("serverops: decoding failing, invalid json")
	ErrDecodeInvalidYAML      = errors.New("serverops: decoding failing, invalid yaml")
	ErrDecodeBase64           = errors.New("serverops: decoding failing, invalid base64 data")
	ErrUnsupportedContentType = errors.New("serverops: unsupported content type for decoding")
	ErrReadingRequestBody     = errors.New("serverops: failed to read request body")
	ErrMalformedContentType   = errors.New("serverops: malformed Content-Type header")
)
View Source
var (
	ErrInvalidParameterValue = errors.New("serverops: invalid parameter value type")
	ErrBadPathValue          = errors.New("serverops: bad path value")
	ErrImmutableModel        = errors.New("serverops: immutable model")
	ErrImmutablePool         = errors.New("serverops: immutable pool")
	ErrMissingParameter      = errors.New("serverops: missing parameter")
	ErrEmptyRequest          = errors.New("serverops: empty request")
	ErrEmptyRequestBody      = errors.New("serverops: empty request body")
)
View Source
var (
	// ErrBadRequest is a generic error for a 400 Bad Request
	ErrBadRequest = errors.New("serverops: bad request")
	// ErrUnprocessableEntity is a generic error for a 422 Unprocessable Entity
	ErrUnprocessableEntity = errors.New("serverops: unprocessable entity")
	// ErrNotFound is a generic error for a 404 Not Found
	ErrNotFound = errors.New("serverops: not found")
	// ErrConflict is a generic error for a 409 Conflict
	ErrConflict = errors.New("serverops: conflict")
	// ErrForbidden is a generic error for a 403 Forbidden
	ErrForbidden = errors.New("serverops: forbidden")
	// ErrInternalServerError is a generic error for a 500 Internal Server Error
	ErrInternalServerError = errors.New("serverops: internal server error")
	// ErrUnsupportedMediaType is a generic error for a 415 Unsupported Media Type
	ErrUnsupportedMediaType = errors.New("serverops: unsupported media type")
	// ErrUnauthorized is a generic error for a 401 Unauthorized
	ErrUnauthorized = errors.New("serverops: unauthorized")
)

The generic error types for common HTTP status codes

View Source
var ErrFileEmpty = errors.New("serverops: file cannot be empty")

ErrFileEmpty indicates an attempt to upload an empty file.

View Source
var ErrFileSizeLimitExceeded = errors.New("serverops: file size limit exceeded")

ErrFileSizeLimitExceeded indicates the specific file exceeded its allowed size limit.

View Source
var ErrInvalidChain = errors.New("invalid chain definition")

Functions

func Decode

func Decode[T any](r *http.Request) (T, error)

func Encode

func Encode[T any](w http.ResponseWriter, _ *http.Request, status int, v T) error

func EnforceToken added in v0.0.17

func EnforceToken(token string, next http.Handler) http.Handler

func Error

func Error(w http.ResponseWriter, r *http.Request, err error, op Operation) error

Error sends a JSON-encoded error response with an appropriate status code

func GetVersion added in v0.0.25

func GetVersion() string

func HandleAPIError added in v0.0.4

func HandleAPIError(resp *http.Response) error

HandleAPIError processes error responses from the API

func IsAPIError added in v0.0.4

func IsAPIError(err error) bool

IsAPIError checks if an error is an APIError

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

func TokenMiddleware added in v0.0.17

func TokenMiddleware(next http.Handler) http.Handler

func TracingMiddleware added in v0.0.17

func TracingMiddleware(next http.Handler) http.Handler

TracingMiddleware extracts or generates trace and span IDs.

Types

type APIError added in v0.0.4

type APIError struct {
	ErrorProperty string `json:"error"`
}

APIError represents an error response from the API

func (*APIError) Error added in v0.0.4

func (e *APIError) Error() string

type AboutServer added in v0.0.25

type AboutServer struct {
	Version        string `json:"version"`
	NodeInstanceID string `json:"nodeInstanceID"`
	Tenancy        string `json:"tenancy"`
}

type ContextKey added in v0.0.17

type ContextKey string
const (
	ContextTokenKey ContextKey = "token"
)

type Operation

type Operation uint16
const (
	CreateOperation Operation = iota
	GetOperation
	UpdateOperation
	DeleteOperation
	ListOperation
	AuthorizeOperation
	ServerOperation
	ExecuteOperation
)

Jump to

Keyboard shortcuts

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