fxhttpserver

package
v0.0.0-...-4ef61cc Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort       = 8080
	HeaderXRequestId  = "x-request-id"
	HeaderTraceParent = "traceparent"
)

Variables

Functions

func AsHandler

func AsHandler(method string, path string, handler any, middlewares ...any) fx.Option

func AsHandlersGroup

func AsHandlersGroup(prefix string, handlersRegistrations []*HandlerRegistration, middlewares ...any) fx.Option

func AsMiddleware

func AsMiddleware(middleware any, kind MiddlewareKind) fx.Option

func CtxAuthenticationContext

func CtxAuthenticationContext(c echo.Context) (*fxauthenticationcontext.AuthenticationContext, error)

func CtxHttpClient

func CtxHttpClient(c echo.Context, opts ...fxhttpclient.HttpClientOption) *fxhttpclient.HttpClient

func CtxLogger

func CtxLogger(c echo.Context) *fxlogger.Logger

func CtxTracer

func CtxTracer(c echo.Context) trace.Tracer

func NewFxHttpServer

func NewFxHttpServer(p FxHttpServerParam) (*echo.Echo, error)

func NewHttpServerErrorHandler

func NewHttpServerErrorHandler(config *fxconfig.Config) echo.HTTPErrorHandler

func RegisterHandler

func RegisterHandler(handlerRegistration *HandlerRegistration) fx.Option

func RegisterHandlersGroup

func RegisterHandlersGroup(handlersGroupRegistration *HandlersGroupRegistration) fx.Option

func RegisterMiddleware

func RegisterMiddleware(middlewareRegistration *MiddlewareRegistration) fx.Option

func StartFxHttpServer

func StartFxHttpServer() fx.Option

Types

type DefaultHttpServerFactory

type DefaultHttpServerFactory struct{}

func (*DefaultHttpServerFactory) Create

func (f *DefaultHttpServerFactory) Create(options ...HttpServerOption) (*echo.Echo, error)

type EchoLogger

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

func NewEchoLogger

func NewEchoLogger(logger *fxlogger.Logger) *EchoLogger

func (*EchoLogger) Debug

func (e *EchoLogger) Debug(i ...interface{})

func (*EchoLogger) Debugf

func (e *EchoLogger) Debugf(format string, args ...interface{})

func (*EchoLogger) Debugj

func (e *EchoLogger) Debugj(j log.JSON)

func (*EchoLogger) Error

func (e *EchoLogger) Error(i ...interface{})

func (*EchoLogger) Errorf

func (e *EchoLogger) Errorf(format string, args ...interface{})

func (*EchoLogger) Errorj

func (e *EchoLogger) Errorj(j log.JSON)

func (*EchoLogger) Fatal

func (e *EchoLogger) Fatal(i ...interface{})

func (*EchoLogger) Fatalf

func (e *EchoLogger) Fatalf(format string, args ...interface{})

func (*EchoLogger) Fatalj

func (e *EchoLogger) Fatalj(j log.JSON)

func (*EchoLogger) Info

func (e *EchoLogger) Info(i ...interface{})

func (*EchoLogger) Infof

func (e *EchoLogger) Infof(format string, args ...interface{})

func (*EchoLogger) Infoj

func (e *EchoLogger) Infoj(j log.JSON)

func (*EchoLogger) Level

func (e *EchoLogger) Level() log.Lvl

func (*EchoLogger) Output

func (e *EchoLogger) Output() io.Writer

func (*EchoLogger) Panic

func (e *EchoLogger) Panic(i ...interface{})

func (*EchoLogger) Panicf

func (e *EchoLogger) Panicf(format string, args ...interface{})

func (*EchoLogger) Panicj

func (e *EchoLogger) Panicj(j log.JSON)

func (*EchoLogger) Prefix

func (e *EchoLogger) Prefix() string

func (*EchoLogger) Print

func (e *EchoLogger) Print(i ...interface{})

func (*EchoLogger) Printf

func (e *EchoLogger) Printf(format string, i ...interface{})

func (*EchoLogger) Printj

func (e *EchoLogger) Printj(j log.JSON)

func (*EchoLogger) SetHeader

func (e *EchoLogger) SetHeader(h string)

func (*EchoLogger) SetLevel

func (e *EchoLogger) SetLevel(v log.Lvl)

func (*EchoLogger) SetLogger

func (e *EchoLogger) SetLogger(logger *fxlogger.Logger) *EchoLogger

func (*EchoLogger) SetOutput

func (e *EchoLogger) SetOutput(w io.Writer)

func (*EchoLogger) SetPrefix

func (e *EchoLogger) SetPrefix(p string)

func (*EchoLogger) ToZerolog

func (e *EchoLogger) ToZerolog() *zerolog.Logger

func (*EchoLogger) Warn

func (e *EchoLogger) Warn(i ...interface{})

func (*EchoLogger) Warnf

func (e *EchoLogger) Warnf(format string, args ...interface{})

func (*EchoLogger) Warnj

func (e *EchoLogger) Warnj(j log.JSON)

type FxHttpServerParam

type FxHttpServerParam struct {
	fx.In
	LifeCycle      fx.Lifecycle
	Factory        HttpServerFactory
	Registry       *HttpServerRegistry
	Config         *fxconfig.Config
	Logger         *fxlogger.Logger
	TracerProvider *trace.TracerProvider
	HealthChecker  *fxhealthchecker.HealthChecker
}

type FxHttpServerRegistryParam

type FxHttpServerRegistryParam struct {
	fx.In
	Middlewares              []Middleware              `group:"http-server-middlewares"`
	MiddlewareDefinitions    []MiddlewareDefinition    `group:"http-server-middleware-definitions"`
	Handlers                 []Handler                 `group:"http-server-handlers"`
	HandlerDefinitions       []HandlerDefinition       `group:"http-server-handler-definitions"`
	HandlersGroupDefinitions []HandlersGroupDefinition `group:"http-server-handlers-group-definitions"`
}

type Handler

type Handler interface {
	Handle() echo.HandlerFunc
}

type HandlerDefinition

type HandlerDefinition interface {
	Concrete() bool
	Method() string
	Path() string
	Handler() any
	Middlewares() []MiddlewareDefinition
}

type HandlerRegistration

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

func NewHandlerRegistration

func NewHandlerRegistration(method string, path string, handler any, middlewares ...any) *HandlerRegistration

func (*HandlerRegistration) Handler

func (h *HandlerRegistration) Handler() any

func (*HandlerRegistration) Method

func (h *HandlerRegistration) Method() string

func (*HandlerRegistration) Middlewares

func (h *HandlerRegistration) Middlewares() []any

func (*HandlerRegistration) Path

func (h *HandlerRegistration) Path() string

type HandlersGroupDefinition

type HandlersGroupDefinition interface {
	Prefix() string
	Handlers() []HandlerDefinition
	Middlewares() []MiddlewareDefinition
}

type HandlersGroupRegistration

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

func NewHandlersGroupRegistration

func NewHandlersGroupRegistration(prefix string, handlersRegistrations []*HandlerRegistration, middlewares ...any) *HandlersGroupRegistration

func (*HandlersGroupRegistration) HandlersRegistrations

func (h *HandlersGroupRegistration) HandlersRegistrations() []*HandlerRegistration

func (*HandlersGroupRegistration) Middlewares

func (h *HandlersGroupRegistration) Middlewares() []any

func (*HandlersGroupRegistration) Prefix

func (h *HandlersGroupRegistration) Prefix() string

type HttpServerFactory

type HttpServerFactory interface {
	Create(options ...HttpServerOption) (*echo.Echo, error)
}

func NewDefaultHttpServerFactory

func NewDefaultHttpServerFactory() HttpServerFactory

type HttpServerOption

type HttpServerOption func(o *options)

func WithBanner

func WithBanner(b bool) HttpServerOption

func WithBinder

func WithBinder(b echo.Binder) HttpServerOption

func WithDebug

func WithDebug(d bool) HttpServerOption

func WithHttpErrorHandler

func WithHttpErrorHandler(h echo.HTTPErrorHandler) HttpServerOption

func WithJsonSerializer

func WithJsonSerializer(s echo.JSONSerializer) HttpServerOption

func WithLogger

func WithLogger(l echo.Logger) HttpServerOption

type HttpServerRegistry

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

func (*HttpServerRegistry) LookupRegisteredHandler

func (r *HttpServerRegistry) LookupRegisteredHandler(handler string) (Handler, error)

func (*HttpServerRegistry) LookupRegisteredMiddleware

func (r *HttpServerRegistry) LookupRegisteredMiddleware(middleware string) (Middleware, error)

func (*HttpServerRegistry) ResolveHandlers

func (r *HttpServerRegistry) ResolveHandlers() ([]ResolvedHandler, error)

func (*HttpServerRegistry) ResolveHandlersGroups

func (r *HttpServerRegistry) ResolveHandlersGroups() ([]ResolvedHandlersGroup, error)

func (*HttpServerRegistry) ResolveMiddlewares

func (r *HttpServerRegistry) ResolveMiddlewares() ([]ResolvedMiddleware, error)

type Middleware

type Middleware interface {
	Handle() echo.MiddlewareFunc
}

type MiddlewareDefinition

type MiddlewareDefinition interface {
	Concrete() bool
	Middleware() any
	Kind() MiddlewareKind
}

type MiddlewareKind

type MiddlewareKind int
const (
	GlobalUse MiddlewareKind = iota
	GlobalPre
	Attached
)

func (MiddlewareKind) String

func (k MiddlewareKind) String() string

type MiddlewareRegistration

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

func NewMiddlewareRegistration

func NewMiddlewareRegistration(middleware any, kind MiddlewareKind) *MiddlewareRegistration

func (*MiddlewareRegistration) Kind

func (*MiddlewareRegistration) Middleware

func (m *MiddlewareRegistration) Middleware() any

type ResolvedHandler

type ResolvedHandler interface {
	Method() string
	Path() string
	Handler() echo.HandlerFunc
	Middlewares() []echo.MiddlewareFunc
}

type ResolvedHandlersGroup

type ResolvedHandlersGroup interface {
	Prefix() string
	Handlers() []ResolvedHandler
	Middlewares() []echo.MiddlewareFunc
}

type ResolvedMiddleware

type ResolvedMiddleware interface {
	Middleware() echo.MiddlewareFunc
	Kind() MiddlewareKind
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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