Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInternalError = fmt.Errorf("internal server error")
Functions ¶
func HandleWithContext ¶
func HandleWithContext[T any](h func(http.ResponseWriter, *http.Request, T), ctx T) http.HandlerFunc
func NewClientError ¶
NewAppError creates a new application error
Types ¶
type ClientError ¶
AppError holds information about an application error
func (ClientError) As ¶
func (c ClientError) As(target error) bool
func (*ClientError) Body ¶
func (c *ClientError) Body() []byte
Body formats the application error for the caller
type ErrHandler ¶
errHandler contains a handler that returns an error and a logger
func (*ErrHandler) ServeHTTP ¶
func (e *ErrHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP satisfies the http.Handler interface to allow for handling of errors from handlers in one place
type Server ¶
type Server struct { Logger *logr.Logger Router *http.ServeMux Exporter *metrics.Exporter TracerProvider *trace.TracerProvider // contains filtered or unexported fields }
Server holds the http.Server, a logger, and the router to attach to the http.Server
func NewHTTPServer ¶
func NewHTTPServer(opts ...ServerOption) *Server
NewHTTPServer initializes and returns a new Server
func (*Server) AutoHandleErrors ¶
AutoHandleErrors is a convenience that should be called after starting the server. It will automatically safely stop the server if a signal is received. This breaks the normal pattern of letting the caller handle fatal errors, which is why this is a convenience function that's able to be called separately.
func (*Server) RegisterSubRouter ¶
func (s *Server) RegisterSubRouter(prefix string, routes []Route, middleware ...func(http.Handler) http.Handler) *Server
RegisterSubRouter creates a subrouter based on a path and a slice of routes. Any middlewares passed in will be mounted to the sub router
func (*Server) ShutdownServer ¶
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is a functional option to modify the server
func SetIdleTimeout ¶
func SetIdleTimeout(t int) ServerOption
SetIdleTimeout sets the http.Server idle timeout
func SetReadTimeout ¶
func SetReadTimeout(t int) ServerOption
SetReadTimeout sets the http.Server read timeout
func SetServerPort ¶
func SetServerPort(p int) ServerOption
SetServerPort sets the server listening port
func SetTracerProvider ¶
func SetTracerProvider(t *trace.TracerProvider) ServerOption
func SetWriteTimeout ¶
func SetWriteTimeout(t int) ServerOption
SetWriteTimeout sets the http.Server write timeout