server

package
v0.0.0-...-a7142db Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

LoggingMiddleware creates a new logging middleware

Types

type App

type App struct {
	Logger *zerolog.Logger
	// contains filtered or unexported fields
}

App struct with middleware support

func NewApp

func NewApp(router Router, ctx context.Context, logger *zerolog.Logger, registrars ...RouteRegistrar) *App

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*App) SetupRoutes

func (a *App) SetupRoutes()

func (*App) SetupServer

func (a *App) SetupServer(g *errgroup.Group)

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) error

func (*App) Start

func (a *App) Start() error

type DebugRegistrar

type DebugRegistrar struct{}

func (*DebugRegistrar) RegisterRoutes

func (dr *DebugRegistrar) RegisterRoutes(router Router)

type DefaultRouter

type DefaultRouter struct {

	// endpoints is the list of all registered endpoints
	Endpoints []Endpoint
	// contains filtered or unexported fields
}

DefaultRouter

func NewDefaultRouter

func NewDefaultRouter(prefix string) *DefaultRouter

NewDefaultRouter creates a new DefaultRouter with the given prefix

func (*DefaultRouter) Group

func (dr *DefaultRouter) Group(prefix string) *RouterGroup

Group creates a new RouterGroup under the rootGroup with the given prefix

func (*DefaultRouter) Handle

func (r *DefaultRouter) Handle(pattern string, handler http.Handler)

func (*DefaultRouter) HandleFunc

func (dr *DefaultRouter) HandleFunc(pattern string, handlerFunc func(http.ResponseWriter, *http.Request))

func (*DefaultRouter) ServeHTTP

func (r *DefaultRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*DefaultRouter) Use

func (dr *DefaultRouter) Use(middleware ...Middleware)

type Endpoint

type Endpoint struct {
	Method string
	Path   string
}

type MetricsRegistrar

type MetricsRegistrar struct{}

func (*MetricsRegistrar) RegisterRoutes

func (m *MetricsRegistrar) RegisterRoutes(router Router)

type Middleware

type Middleware func(http.Handler) http.Handler

type RouteRegistrar

type RouteRegistrar interface {
	RegisterRoutes(router Router)
}

type Router

type Router interface {
	// Handle registers a new route with the given pattern and handler on the router mux
	Handle(pattern string, handler http.Handler)
	// HandleFunc registers a new route with the given pattern and handler function on the router mux
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	// ServeHTTP would dispatch the request to the default mux
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	// Use adds middleware to the default router
	Use(middleware ...Middleware)
	// Group called on the router would create a group with the given prefix
	//and would inherit the middleware from the router and would be added to the root group of the router
	Group(prefix string) *RouterGroup
}

type RouterGroup

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

RouterGroup represents a group of routes with a common prefix and middleware

func (*RouterGroup) Group

func (rg *RouterGroup) Group(prefix string) *RouterGroup

func (*RouterGroup) Handle

func (rg *RouterGroup) Handle(pattern string, handler http.Handler)

func (*RouterGroup) HandleFunc

func (rg *RouterGroup) HandleFunc(pattern string, handlerFunc func(http.ResponseWriter, *http.Request))

func (*RouterGroup) Use

func (rg *RouterGroup) Use(middleware ...Middleware)

Jump to

Keyboard shortcuts

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