restapi

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecoveryMiddleware

func RecoveryMiddleware(handler http.Handler) http.Handler

func RequestLoggerMiddleware

func RequestLoggerMiddleware(handler http.Handler) http.Handler

Types

type CORSOptions

type CORSOptions struct {
	Origins []string
	Methods []string
	Headers []string
}

type DependencyProvider

type DependencyProvider func(ctx *webcontext.Context) any

type Middleware

type Middleware mux.MiddlewareFunc

type ServerOption

type ServerOption func(server *WebServer) error

func WithCORS

func WithCORS(opts CORSOptions) ServerOption

func WithRecoveryMiddleware

func WithRecoveryMiddleware(middleware Middleware) ServerOption

func WithRequestLoggerMiddleware

func WithRequestLoggerMiddleware(middleware Middleware) ServerOption

func WithTracePropagator added in v0.0.2

func WithTracePropagator(propagator propagation.TextMapPropagator) ServerOption

WithTracePropagator replaces the default propagator with the one provided

func WithTracing added in v0.0.2

func WithTracing(traceName string, tp trace.TracerProvider) ServerOption

WithTracing option adds an OpenTelemetry's tracing SDK implementation to the server

type WebServer

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

func NewWebServer

func NewWebServer(options ...ServerOption) (*WebServer, error)

func (*WebServer) AddDependency

func (w *WebServer) AddDependency(provider DependencyProvider, objProto any)

func (*WebServer) AddMiddlewares

func (w *WebServer) AddMiddlewares(middlewares ...Middleware)

AddMiddlewares adds layers of handler functions to an existing route. Note that the ordering matters here, so the first argument is going to be called first Important Note: NewRequestLoggerMiddleware and NewRecoveryMiddleware are set separatedly, and always at start.

func (*WebServer) AddToContext

func (w *WebServer) AddToContext(key string, value any)

func (*WebServer) InjectAsDependency added in v0.0.5

func (w *WebServer) InjectAsDependency(objects ...any)

func (*WebServer) Route

func (w *WebServer) Route(endpoint string, route any, methods ...string)

Register a new endpoint to be routed to the given route function

func (*WebServer) Run

func (w *WebServer) Run(addr string) error

func (*WebServer) ServeHTTP

func (w *WebServer) ServeHTTP(writer http.ResponseWriter, r *http.Request)

func (*WebServer) Shutdown

func (w *WebServer) Shutdown(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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