package
0.24.0
Repository: https://github.com/lushdigital/core.git
Documentation: pkg.go.dev

# README

HTTP Server

The package core/workers/httpsrv provides a default set of configuration for hosting a http server in a service.

Configuration

The HTTP server can be configured through these environment variables:

  • HTTP_ADDR the HTTP server listener's network address (default: 0.0.0.0:80)

Examples

Starting default server and expose the service

srv := httpsrv.NewDefault(handler)
srv.Run(ctx, os.Stdout)

Starting server with a custom http server

srv := httpsrv.New(&http.Server{
    Handler: Handler,
    ReadTimeout: 1 * time.Second,
})
srv.Run(ctx)

# Functions

CORSHandler updates headers on CORS preflight requests and actual CORS requests.
HealthHandler responds with service health.
New sets up a new HTTP server.
NewDefault returns a http server.
WrapperHandler returns the wrapper handler for the http server.

# Constants

Port is the default HTTP port.

# Variables

DefaultCORS contains the default CORS settings used when starting an httpsrv.Server.
DefaultHTTPServer represents the default configuration for the http server.
NotFoundHandler responds with the default a 404 response.

# Structs

CORS defines a struct which allows configuring the CORS settings for httpsrv.Server.
HealthResponse contains information about the service health.
Server represents a collection of functions for starting and running an RPC server.