serve

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package serve provides a way to create and manage an HTTP server, including routing, middleware, and graceful shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataFunc

type DataFunc func(r *http.Request, data *map[string]any)

DataFunc is a function type that takes an HTTP request and a pointer to a map of data. It represents a callback function that can be used to populate data for templates.

type Server

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

func NewServer

func NewServer(config *conf.HopConfig, logger *slog.Logger, router *route.Mux) *Server

NewServer creates a new server with the given configuration and logger.

func (*Server) BackgroundTask

func (s *Server) BackgroundTask(r *http.Request, fn func() error)

BackgroundTask runs a function in a goroutine, and reports any errors to the server's error logger.

func (*Server) Config added in v0.0.18

func (s *Server) Config() *conf.HopConfig

Config returns the server configuration.

func (*Server) Logger

func (s *Server) Logger() *slog.Logger

Logger returns the logger for the server.

func (*Server) OnShutdown added in v0.0.18

func (s *Server) OnShutdown(fn func(context.Context) error)

OnShutdown registers a shutdown handler to be called before the server stops

func (*Server) ReportServerError

func (s *Server) ReportServerError(r *http.Request, err error)

ReportServerError logs the error and sends an email to the admin

func (*Server) Router added in v0.0.18

func (s *Server) Router() *route.Mux

Router returns the router for the server.

func (*Server) Shutdown added in v0.0.18

func (s *Server) Shutdown(ctx context.Context) error

Shutdown initiates a graceful shutdown of the server

func (*Server) Start

func (s *Server) Start() error

Start starts the server and listens for incoming requests. It will block until the server is shut down.

Jump to

Keyboard shortcuts

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