Documentation ¶
Overview ¶
Package httpsrv provides a default set of configuration for hosting a http server in a service.
Example ¶
package main import ( "context" "net/http" "os" "time" "github.com/LUSHDigital/core/workers/httpsrv" ) var ( handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) return }) ctx context.Context ) func main() { go httpsrv.New(&http.Server{ Handler: handler, ReadTimeout: 1 * time.Second, }).Run(ctx, os.Stdout) }
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const (
// Port is the default HTTP port.
Port = 80
)
Variables ¶
View Source
var ( // NotFoundHandler responds with the default a 404 response. NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { res := &response.Response{ Code: http.StatusNotFound, Message: http.StatusText(http.StatusNotFound), } res.WriteTo(w) }) // DefaultHTTPServer represents the default configuration for the http server DefaultHTTPServer = http.Server{ WriteTimeout: 5 * time.Second, ReadTimeout: 5 * time.Second, IdleTimeout: 5 * time.Second, ReadHeaderTimeout: 1 * time.Second, } )
Functions ¶
func HealthHandler ¶
func HealthHandler(now func() time.Time) http.HandlerFunc
HealthHandler responds with service health.
func WrapperHandler ¶
WrapperHandler returns the wrapper handler for the http server.
Types ¶
type HealthResponse ¶
type HealthResponse struct { Latency string `json:"latency"` StackInUse string `json:"stack_in_use"` HeapInUse string `json:"heap_in_use"` HeapAlloc string `json:"heap_alloc"` NumGoRoutines int `json:"num_go_routines"` }
HealthResponse contains information about the service health.
type Server ¶
type Server struct { Server *http.Server Now func() time.Time // contains filtered or unexported fields }
Server represents a collection of functions for starting and running an RPC server.
func NewDefault ¶ added in v0.5.0
NewDefault returns a http server
Click to show internal directories.
Click to hide internal directories.