api

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package api implements echo http server handlers and boilerplate code

Index

Constants

View Source
const (
	// LivenessPath endpoint default path
	LivenessPath = "/healthz"

	// ReadinessPath endpoint default path
	ReadinessPath = "/readyz"

	// StatusHealthy means that service in health state
	StatusHealthy = Status("StatusHealthy")

	// StatusUnhealthy means that service is in degraded state
	StatusUnhealthy = Status("StatusUnhealthy")
)
View Source
const (
	// DefaultNamespaceValue is default OTA namespace
	DefaultNamespaceValue = "default"
)

Variables

This section is empty.

Functions

func GetContentSize

func GetContentSize(ctx echo.Context) int64

GetContentSize returns Content length from request header

func GetContentType

func GetContentType(ctx echo.Context) string

GetContentType returns value of ContentType header

func GetNamespace added in v1.0.15

func GetNamespace(ctx echo.Context) data.Namespace

GetNamespace returns OTA namespace from header

func GetRequestContext

func GetRequestContext(ctx echo.Context) context.Context

GetRequestContext return populated request context.Context

func GetRequestID added in v1.0.17

func GetRequestID(ctx echo.Context) string

GetRequestID returns RequestID from header

func HealthzHandler

func HealthzHandler(ctx echo.Context) error

HealthzHandler is a k8s liveness endpoint

func ReadyzHandler

func ReadyzHandler(fns ...func(ctx context.Context) HealthEntryStatus) func(echo.Context) error

ReadyzHandler is a k8s readiness endpoint

func ServerHeader

func ServerHeader(name, version string) echo.MiddlewareFunc

ServerHeader middleware adds a `Server` header to the response.

Types

type ErrorHandler

type ErrorHandler struct {
	Handler echo.HTTPErrorHandler
	// contains filtered or unexported fields
}

ErrorHandler is a wrapper on echo.HTTPErrorHandler

func NewErrorHandler

func NewErrorHandler() *ErrorHandler

NewErrorHandler sets up the mapping of error type to handler

type ErrorResponse

type ErrorResponse struct {
	// ErrorCode application error code
	ErrorCode string `json:"error_code"`
	// StatusCode HTTP response status code
	StatusCode int `json:"status_code"`
	// Description description of error
	Description string `json:"description"`
	// RequestID HTTP requestID go from header of request
	RequestID string `json:"request_id"`
}

ErrorResponse is http error response model

func NewErrorResponse

func NewErrorResponse(ctx context.Context, statusCode int, err error) ErrorResponse

NewErrorResponse creates new error response from error

type HealthEntryStatus

type HealthEntryStatus struct {
	Status   Status      `json:"status"`
	Data     interface{} `json:"data"`
	Resource string      `json:"resource"`
}

HealthEntryStatus is status of external dependency like db or queue

type HealthStatusResponse

type HealthStatusResponse struct {
	Status  Status              `json:"status"`
	Entries []HealthEntryStatus `json:"entries,omitempty"`
}

HealthStatusResponse response of health endpoints

type Status

type Status string

Status of service

Jump to

Keyboard shortcuts

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