server

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InCtxMiddleware

func InCtxMiddleware(key string, value interface{}) func(http.Handler) http.Handler

InCtxMiddleware allows to specify a key/value that should be set on each request context. This is useful for services that could be used by the handlers.

func New

func New(options ...Option) *mux

New creates a new server with the given options and default middleware.

Types

type Middleware added in v1.2.13

type Middleware func(http.Handler) http.Handler

Middleware is a function that receives a http.Handler and returns a http.Handler that can be used to wrap the original handler with some functionality.

type Option

type Option func(*mux)

func WithHost

func WithHost(host string) Option

func WithPort

func WithPort(port string) Option

type Router added in v1.2.13

type Router interface {
	// Use allows to specify a middleware that should be executed for all the handlers
	Use(middleware ...Middleware)

	// Handle allows to register a new handler for a specific pattern
	Handle(pattern string, handler http.Handler)

	// HandleFunc allows to register a new handler function for a specific pattern
	HandleFunc(pattern string, handler http.HandlerFunc)

	// Folder allows to serve static files from a directory
	Folder(prefix string, fs fs.FS)

	// Group allows to create a new group of routes with a common prefix
	Group(prefix string, fn func(Router))
}

Router is the interface that wraps the basic methods for a router

Jump to

Keyboard shortcuts

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