httpserver

package
v0.0.0-...-a670c85 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"httpserver",

	fx.Provide(
		fx.Annotate(
			NewServerConfig,
			fx.ResultTags(`group:routes"`),
			fx.ResultTags("group:middleware"),
		),
	),
)

Functions

func AsPartofMiddlewareCollection

func AsPartofMiddlewareCollection(mw Middleware) any

AsPartofMiddlewareCollection annotates a Middleware for inclusion in an Fx group.

func AsPartofRouteCollection

func AsPartofRouteCollection(route Route) any

AsPartofRouteCollection wraps a Route into an fx.Annotate to be included in a route collection.

func BuildMiddlewareChain

func BuildMiddlewareChain(finalHandler http.Handler, middlewares []Middleware) http.Handler

BuildMiddlewareChain constructs a middleware chain from the provided middlewares and final handler. Middlewares are applied in the order they are provided, meaning the first middleware in the slice will be the outermost one to handle requests.

func NewServer

func NewServer(lc fx.Lifecycle, logger slog.Logger, routeCollection []Route, middlewares []Middleware) *http.Server

NewServer creates and configures a new HTTP server instance. It sets up the server with the provided route collection and middleware stack

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a function that wraps an http.Handler with additional functionality. It receives the next handler in the chain and returns a new handler. Middlewares can choose whether to call the next handler or stop the chain.

type Route

type Route struct {
	Method      string
	Pattern     string
	HandlerFunc func(http.ResponseWriter, *http.Request)
}

func NewRoute

func NewRoute(method, pattern string, handlerFunc func(http.ResponseWriter, *http.Request)) Route

type Router

type Router interface {
	RegisterRoute(route Route)
	Handler() http.Handler
}

func NewRouter

func NewRouter(mux *http.ServeMux) Router

type ServeMuxRouter

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

func (*ServeMuxRouter) Handler

func (r *ServeMuxRouter) Handler() http.Handler

func (*ServeMuxRouter) RegisterRoute

func (r *ServeMuxRouter) RegisterRoute(route Route)

type ServerConfig

type ServerConfig struct {
	Host          string
	Port          int
	AbsPathToKey  string
	AbsPathToCert string
}

func NewServerConfig

func NewServerConfig() *ServerConfig

func (*ServerConfig) Address

func (c *ServerConfig) Address() string

Jump to

Keyboard shortcuts

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