httpserver

package
v0.1.0-alpha.19 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package httpserver provides HTTP server functionality with middleware support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileServer

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

FileServer represents an HTTP file server for serving static files.

func NewFileServer

func NewFileServer(fs fs.FS, basePath, port string) *FileServer

NewFileServer creates a new FileServer instance with the given file system, base path, and port.

func (*FileServer) Run

func (s *FileServer) Run(ctx context.Context) error

Run starts the file server and listens for incoming requests.

func (*FileServer) ServeHTTP

func (s *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HTTPServer

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

HTTPServer represents an HTTP server with middleware support and graceful shutdown.

func New

func New(port string, shutdownTimeout time.Duration) *HTTPServer

New creates a new HTTPServer instance with the specified port and shutdown timeout.

func (*HTTPServer) Healthcheck

func (s *HTTPServer) Healthcheck(_ context.Context) any

Healthcheck returns health check information for the HTTP server.

func (*HTTPServer) Run

func (s *HTTPServer) Run(ctx context.Context) error

Run starts the HTTP server and handles graceful shutdown on interrupt signals.

type HandlerGroup

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

HandlerGroup represents a group of HTTP handlers that share common middlewares.

func NewHandlerGroup

func NewHandlerGroup() *HandlerGroup

NewHandlerGroup creates a new HandlerGroup with an initialized http.ServeMux.

func (*HandlerGroup) Handle

func (hg *HandlerGroup) Handle(pattern string, handler http.Handler)

Handle registers an http.Handler for the given pattern

func (*HandlerGroup) HandleFunc

func (hg *HandlerGroup) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers an http.HandlerFunc for the given pattern

func (*HandlerGroup) HandleGroup

func (hg *HandlerGroup) HandleGroup(pattern string, handler http.Handler)

HandleGroup applies `http.StripPrefix` to http.Handler and registers it for the given pattern

func (*HandlerGroup) ServeHTTP

func (hg *HandlerGroup) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface, allowing HandlerGroup to be used as an HTTP handler itself.

func (*HandlerGroup) Use

func (hg *HandlerGroup) Use(middlewares ...Middleware)

Use adds a middleware to the HandlerGroup's middleware chain.

func (*HandlerGroup) UseFunc

func (hg *HandlerGroup) UseFunc(middlewareFuncs ...func(http.Handler) http.Handler)

UseFunc adds a function as a middleware to the HandlerGroup's middleware chain.

type Middleware

type Middleware interface {
	// Wrap wraps an http.Handler with middleware logic.
	Wrap(http.Handler) http.Handler
}

Middleware defines an interface for HTTP middleware.

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

MiddlewareFunc is a convenience type that implements the Middleware interface.

func (MiddlewareFunc) Wrap

Wrap implements the Middleware interface for MiddlewareFunc.

type RecoverMiddleware

type RecoverMiddleware struct{}

RecoverMiddleware is a middleware that recovers from panics in HTTP handlers. It catches panics, logs the error, and returns an HTTP 500 response to the client.

func NewRecoverMiddleware

func NewRecoverMiddleware() *RecoverMiddleware

NewRecoverMiddleware creates a new instance of RecoverMiddleware.

func (*RecoverMiddleware) Wrap

func (m *RecoverMiddleware) Wrap(next http.Handler) http.Handler

Wrap implements the Middleware interface by wrapping the provided handler with panic recovery logic.

Jump to

Keyboard shortcuts

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