Documentation
¶
Overview ¶
Package web contains web server functions and types
Index ¶
- func GetCtxValue[T any](r *http.Request, key string) (T, bool)
- func Heartbeat(w http.ResponseWriter, _ *http.Request)
- func LoggingMiddleware(next http.Handler) http.Handler
- func RegisterRoutes[A any](this A, mux *http.ServeMux, verb string, handlers HandlerMap[A], ...) int
- func RegisterTasks[A any](this A, mux *http.ServeMux, verb string, tasks HandlerTask[A], ...) int
- func RequestBody[T any](r *http.Request) (T, error)
- func SendActionResponse(w http.ResponseWriter, rq *my.Request, err error)
- func SendDataResponse(w http.ResponseWriter, rq *my.Request, data any, err error)
- func SendError(w http.ResponseWriter, rq *my.Request, err error)
- func SendJSON[T any](w http.ResponseWriter, statusCode int, data T)
- type Config
- type Handler
- type HandlerFn
- type HandlerMap
- type HandlerTask
- type Middleware
- type Response
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCtxValue ¶
GetCtxValue gets the value from the context and type coerces into type T
func Heartbeat ¶
func Heartbeat(w http.ResponseWriter, _ *http.Request)
Heartbeat is a health check web endpoint
func LoggingMiddleware ¶
LoggingMiddleware prints the request timestamp, method, path, and duration
func RegisterRoutes ¶
func RegisterRoutes[A any](this A, mux *http.ServeMux, verb string, handlers HandlerMap[A], middlewares ...Middleware) int
RegisterRoutes adds handlers to the router
func RegisterTasks ¶
func RegisterTasks[A any](this A, mux *http.ServeMux, verb string, tasks HandlerTask[A], middlewares ...Middleware) int
RegisterTasks adds handlers to the routers from the tasks
func RequestBody ¶
RequestBody reads the request body into struct type T
func SendActionResponse ¶
func SendActionResponse(w http.ResponseWriter, rq *my.Request, err error)
SendActionResponse sends a Response to the client indicating whether the action was successful
func SendDataResponse ¶
SendDataResponse sends a data Response to the client
Types ¶
type Config ¶
func LoadConfig ¶
LoadConfig loads the web Config from path
type Handler ¶
type Handler = http.HandlerFunc
type HandlerMap ¶
type HandlerTask ¶
type Middleware ¶
func StackMiddlewares ¶
func StackMiddlewares(middlewares ...Middleware) Middleware
StackMiddlewares combines multiple middlewares into a single middleware
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) SetHandler ¶
SetHandler sets the server's http handler