server

package
v0.0.0-...-754897d Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(routes ...Route) http.Handler

NewRouter creates a http.Handler to route endpoints for a JSON API.

func RecovererMiddleware

func RecovererMiddleware(next http.Handler) http.Handler

RecovererMiddleware recovers panics in an HTTP handler and logs the panic via Chi.

func RequestID

func RequestID(req *http.Request) uuid.UUID

RequestID retrieves the request id from the context.

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

RequestIDMiddleware creates random request ids and adds them to the request context.

Types

type Config

type Config struct {
	Addr string
}

type RequestLogEntry

type RequestLogEntry struct {
	Request *http.Request
}

RequestLogEntry implements Chi middleware.LogEntry to log requests and panics via Apex log.

func (RequestLogEntry) Panic

func (rle RequestLogEntry) Panic(val interface{}, stack []byte)

func (RequestLogEntry) Write

func (rle RequestLogEntry) Write(status, bytes int, elapsed time.Duration)

type RequestLogger

type RequestLogger struct{}

RequestLogger implements Chi middleware.LogFormatter to log requests via Apex log.

func (RequestLogger) NewLogEntry

func (rl RequestLogger) NewLogEntry(req *http.Request) middleware.LogEntry

type Route

type Route struct {
	Method      string
	Path        string
	Middlewares []func(http.Handler) http.Handler
	Handler     http.HandlerFunc
}

Route is a single route that has a handler and a list of middleware for the handler.

type Server

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

Server implements a graceful HTTP server.

func New

func New(handler http.Handler, config Config) *Server

func (*Server) Serve

func (s *Server) Serve() error

Serve starts the HTTP server and serves requests until SIGINT or SIGTERM.

Jump to

Keyboard shortcuts

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