apiframework

package
v0.0.76 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 19 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")
	ErrImmutableGroup        = errors.New("serverops: immutable group")
	ErrMissingParameter      = errors.New("serverops: missing parameter")
	ErrEmptyRequest          = errors.New("serverops: empty request")
	ErrEmptyRequestBody      = errors.New("serverops: empty request body")
	ErrInvalidChain          = errors.New("serverops: invalid chain definition")

	// The generic error types for common HTTP status codes
	ErrBadRequest            = errors.New("serverops: bad request")
	ErrUnprocessableEntity   = errors.New("serverops: unprocessable entity")
	ErrNotFound              = errors.New("serverops: not found")
	ErrConflict              = errors.New("serverops: conflict")
	ErrForbidden             = errors.New("serverops: forbidden")
	ErrInternalServerError   = errors.New("serverops: internal server error")
	ErrUnsupportedMediaType  = errors.New("serverops: unsupported media type")
	ErrUnauthorized          = errors.New("serverops: unauthorized")
	ErrFileSizeLimitExceeded = errors.New("serverops: file size limit exceeded")
	ErrFileEmpty             = errors.New("serverops: file cannot be empty")
)

Standard error constants

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

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

func Error

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

func GetErrorParam added in v0.0.68

func GetErrorParam(err error) string

GetErrorParam extracts parameter from error if available.

func GetPathParam

func GetPathParam(r *http.Request, name string, description string) string

GetPathParam retrieves a URL path parameter by name and is used to enforce that all path parameters are documented for the OpenAPI generator. The description argument is not used at runtime but is required for API spec generation.

func GetQueryParam

func GetQueryParam(r *http.Request, name, defaultValue, description string) string

GetQueryParam retrieves a URL query parameter by name. If the parameter is not present, it returns the provided defaultValue. The description is used for OpenAPI generation.

func GetVersion

func GetVersion() string

func HandleAPIError

func HandleAPIError(resp *http.Response) error

HandleAPIError processes error responses from the API

func IsAPIError

func IsAPIError(err error) (message, errorCode, errorType, param string, ok bool)

IsAPIError checks if an error is an APIError and returns its components.

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

func TokenMiddleware

func TokenMiddleware(next http.Handler) http.Handler

func TracingMiddleware

func TracingMiddleware(next http.Handler) http.Handler

TracingMiddleware extracts or generates trace and span IDs.

Types

type APIError

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

APIError wraps an error with parameter context for API responses.

func BadPathValue added in v0.0.68

func BadPathValue(param string, message ...string) *APIError

func BadRequest added in v0.0.68

func BadRequest(message ...string) *APIError

func Conflict added in v0.0.68

func Conflict(message ...string) *APIError

func FileEmpty added in v0.0.68

func FileEmpty(message ...string) *APIError

func FileSizeLimitExceeded added in v0.0.68

func FileSizeLimitExceeded(message ...string) *APIError

func Forbidden added in v0.0.68

func Forbidden(message ...string) *APIError

func ImmutableGroup added in v0.0.68

func ImmutableGroup(message ...string) *APIError

func ImmutableModel added in v0.0.68

func ImmutableModel(message ...string) *APIError

func InternalServerError added in v0.0.68

func InternalServerError(message ...string) *APIError

func InvalidChain added in v0.0.68

func InvalidChain(message ...string) *APIError

func InvalidParameterValue added in v0.0.68

func InvalidParameterValue(param string, message ...string) *APIError

Specific Error Constructors

func MissingParameter added in v0.0.68

func MissingParameter(param string, message ...string) *APIError

func NewAPIError added in v0.0.68

func NewAPIError(err error, message, param string) *APIError

NewAPIError creates a generic APIError with context. If message is empty, it falls back to the underlying error's message.

func NotFound added in v0.0.68

func NotFound(message ...string) *APIError

func Unauthorized added in v0.0.68

func Unauthorized(message ...string) *APIError

func UnprocessableEntity added in v0.0.68

func UnprocessableEntity(message ...string) *APIError

func UnsupportedMediaType added in v0.0.68

func UnsupportedMediaType(message ...string) *APIError

func (*APIError) Code added in v0.0.68

func (e *APIError) Code() string

Code returns the error code.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) Param added in v0.0.68

func (e *APIError) Param() string

Param returns the parameter associated with the error.

func (*APIError) Unwrap added in v0.0.68

func (e *APIError) Unwrap() error

Unwrap returns the underlying error.

type AboutServer

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

type ContextKey

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

type Operation

type Operation uint16

Operation defines API operation types for error mapping

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