httpServer

package
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	Bind() string
	Port() int
	LogRequests() bool
}

type Environment

type Environment struct {
	Statistics Statistics
}

Our application wide data containers

type Error

type Error interface {
	error
	Status() int
}

Error represents a handler error. It provides methods for a HTTP status code and embeds the built-in error interface.

func HandleApiNotFound

func HandleApiNotFound(env *Environment, w http.ResponseWriter, r *http.Request) Error

func HandleStatsCounts

func HandleStatsCounts(env *Environment, w http.ResponseWriter, r *http.Request) Error

type Handler

type Handler struct {
	Env    *Environment
	Handle HandlerHandleFunc
}

The Handler struct that takes a configured Environment and a function matching our useful signature.

func (Handler) ServeHTTP

func (handler Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows our Handler type to satisfy httpServer.Handler.

type HandlerHandleFunc

type HandlerHandleFunc func(e *Environment, w http.ResponseWriter, r *http.Request) Error

define an extended version of http.HandlerFunc

type HttpRoute

type HttpRoute struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc HandlerHandleFunc
}

type HttpServer

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

func Run

func Run(config Config, env *Environment) (httpServer *HttpServer)

func (*HttpServer) Shutdown

func (s *HttpServer) Shutdown()

type Statistics

type Statistics interface {
	Enabled() bool
	GetHierarchicalCountsStructless() interface{}
}

type StatusError

type StatusError struct {
	Code int
	Err  error
}

StatusError represents an error with an associated HTTP status code.

func (StatusError) Error

func (statusError StatusError) Error() string

Allows StatusError to satisfy the error interface.

func (StatusError) Status

func (statusError StatusError) Status() int

Returns our HTTP status code.

Jump to

Keyboard shortcuts

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