httpserver

package
v0.0.0-...-6b07fe0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxApiStart    = "__CTX_APISTART"
	CtxRequestId   = "__CTX_REQUEST_ID"
	CtxDeviceId    = "__CTX_DEVICE_ID"
	CtxRequestUser = "__CTX_REQUEST_USER"
	CtxRequestLog  = "__CTX_REQUEST_LOGLINE"
	CtxRequestTags = "__CTX_REQUEST_TAGS"
)

Variables

View Source
var (
	DURATION_SECONDS_BUCKET = []float64{0.0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 3.0, 5.0, 7.5, 10.0}
)
View Source
var DefaultOutChain = []OutFilter{Jsonize, LogResponseStats}

Functions

func GetIdToken

func GetIdToken(headers http.Header) string

func HttpStatusCodeToError

func HttpStatusCodeToError(statusCode int) error

func InitRequest

func InitRequest(ctx context.Context, request *http.Request) (context.Context, error)

func Jsonize

func Jsonize(_ context.Context, request interface{}, err error) ([]byte, int)

func LogResponseStats

func LogResponseStats(ctx context.Context, _ interface{}, err error) ([]byte, int)

Types

type Endpoint

type Endpoint struct {
	Handler      Handler
	ErrorHandler Handler
	InputFilters []InFilter
	OutFilters   []OutFilter
}

type ErrBadRequest

type ErrBadRequest struct {
	Message string `json:"message"`
}

func (ErrBadRequest) Error

func (e ErrBadRequest) Error() string

func (ErrBadRequest) HttpCode

func (e ErrBadRequest) HttpCode() int

type ErrForbidden

type ErrForbidden struct {
	Message string `json:"message"`
}

func (ErrForbidden) Error

func (e ErrForbidden) Error() string

func (ErrForbidden) HttpCode

func (e ErrForbidden) HttpCode() int

type ErrInternalServerError

type ErrInternalServerError struct {
	Message string `json:"message"`
}

func (ErrInternalServerError) Error

func (e ErrInternalServerError) Error() string

func (ErrInternalServerError) HttpCode

func (e ErrInternalServerError) HttpCode() int

type ErrNotFound

type ErrNotFound struct {
	Message string `json:"message"`
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

func (ErrNotFound) HttpCode

func (e ErrNotFound) HttpCode() int

type ErrPaymentRequired

type ErrPaymentRequired struct {
	Message string `json:"message"`
}

func (ErrPaymentRequired) Error

func (e ErrPaymentRequired) Error() string

func (ErrPaymentRequired) HttpCode

func (e ErrPaymentRequired) HttpCode() int

type ErrRedirect

type ErrRedirect struct {
	RedirectUrl string
}

func (ErrRedirect) Error

func (e ErrRedirect) Error() string

func (ErrRedirect) HttpCode

func (e ErrRedirect) HttpCode() int

type ErrUnauthorized

type ErrUnauthorized struct {
	Message string `json:"message"`
}

func (ErrUnauthorized) Error

func (e ErrUnauthorized) Error() string

func (ErrUnauthorized) HttpCode

func (e ErrUnauthorized) HttpCode() int

type Handler

type Handler func(ctx context.Context, request *http.Request) (interface{}, error)

Handler deprecated is responsible to handle an http request. DO NOT USE DIRECTLY! Use WrapHandler(HandlerFunc) to have typed return values

func WrapHandler

func WrapHandler[T any](handler HandlerFunc[T]) Handler

type HandlerFunc

type HandlerFunc[T any] func(ctx context.Context, request *http.Request) (T, error)

HandlerFunc is responsible to handle an http request

type HttpServer

type HttpServer struct {
	StopChan chan bool
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(service Service) *HttpServer

func (*HttpServer) StartAsync

func (s *HttpServer) StartAsync(host string, port int)

func (*HttpServer) Stop

func (s *HttpServer) Stop() error

type InFilter

type InFilter func(ctx context.Context, request *http.Request) (context.Context, error)

InFilter functions are executed before the handler. The output of any last non-nil

func GlobalAuthHandler

func GlobalAuthHandler(auth0Audience string, auth0CertUrl string, projectId string) InFilter

GlobalAuthHandler is a middleware that checks for a valid JWT token in the Authorization header. Currently it supports Firebase and Auth0 JWT tokens (check auth_auth0.go and auth_firebase.go).

func StaticTokenAuthHandler

func StaticTokenAuthHandler(allowedTokens map[string]string) InFilter

StaticTokenAuthHandler return a handler that check for a token defined in the input map. Only the key is matched

type OutFilter

type OutFilter func(ctx context.Context, request interface{}, err error) ([]byte, int)

OutFilter functions are processed in order. If

type Service

type Service interface {
	StartupProbe(ctx context.Context, r *http.Request) (interface{}, error)
	LivenessProbe(ctx context.Context, r *http.Request) (interface{}, error)
	ReadinessProbe(ctx context.Context, r *http.Request) (interface{}, error)
	Endpoints() map[string]map[string]Endpoint
	WsEndpoints() map[string]WsEndpoint
	DeploymentEnvironment() string
}

type UserId

type UserId string

type WsEndpoint

type WsEndpoint struct {
	WsHandler    WsHandler
	InputFilters []InFilter
}

type WsHandler

type WsHandler func(ctx context.Context, w http.ResponseWriter, r *http.Request)

WsHandler is a low level handler for websockets

Jump to

Keyboard shortcuts

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