httpserver

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthenticatedUserKey key = iota + 1
)

Variables

View Source
var (
	ErrUnauthorized     = errors.New("unauthorized")
	ErrServiceUnhealthy = errors.New("HTTP service unhealthy")
	ErrDecode           = errors.New("can't decode JSON message")
)

Functions

func AddValueToContext

func AddValueToContext(r *http.Request, key key, value interface{}) *http.Request

func GetAuthenticatedUser

func GetAuthenticatedUser(r *http.Request) (*letterbox.User, error)

func GetMailboxByURLPath

func GetMailboxByURLPath(r *http.Request, db letterbox.Datastore) (*letterbox.Mailbox, error)

func ReverseStringSlice

func ReverseStringSlice(s []string) []string

Types

type AppEndpoint

type AppEndpoint struct {
	Handler AppHandler
	Server  *HTTPService
}

func (AppEndpoint) ServeHTTP

func (a AppEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

type AppHandler

type AppHandler func(http.ResponseWriter, *http.Request) (interface{}, error)

type Config

type Config struct {
	MaxShutdownTime time.Duration `json:"max_shutdown_time,omitempty"`
	Port            int           `json:"port,omitempty"`
}

func (*Config) Validate

func (c *Config) Validate() error

type EndpointMetricsMiddleware

type EndpointMetricsMiddleware struct {
	MetricsCollector middleware.Middleware
}

func (*EndpointMetricsMiddleware) AddMiddleware

func (m *EndpointMetricsMiddleware) AddMiddleware(path string, handler http.Handler) http.Handler

type HTTPService

type HTTPService struct {
	Config Config

	PerRouteMiddlewares []PerRouteMiddleware
	Router              *httprouter.Router
	IsHealthy           int32
	MaxShutdownTime     time.Duration

	// Service Dependencies
	DB         letterbox.Datastore
	Logger     *logger.Logger
	ServerInfo *letterbox.Info
	Hasher     letterbox.ArgonHasher
	// contains filtered or unexported fields
}

func (*HTTPService) AddEndpoint

func (s *HTTPService) AddEndpoint(handler AppHandler) *AppEndpoint

func (*HTTPService) Name

func (s *HTTPService) Name() string

func (*HTTPService) Route

func (s *HTTPService) Route(method, path string, handler http.Handler)

func (*HTTPService) Start

func (s *HTTPService) Start() error

func (*HTTPService) Stop

func (s *HTTPService) Stop() error

func (*HTTPService) SubRoute

func (s *HTTPService) SubRoute(path string) *SubRouter

type Middleware

type Middleware func(http.Handler) http.Handler

func AuthMiddleware

func AuthMiddleware(s *HTTPService) Middleware

func BadActorMiddleware

func BadActorMiddleware(s *HTTPService) Middleware

type PerRouteMiddleware

type PerRouteMiddleware interface {
	AddMiddleware(path string, handler http.Handler) http.Handler
}

PerRouteMiddleware adds middleware that requires information about the specific paths used (e.g. HTTP metric collection, which needs to know what path a given function is registered to).

type SubRouter

type SubRouter struct {
	// The full path prefix that this SubRouter is adding to
	Path string
	// The router to add routes to
	Server *HTTPService
	// Middleware to append to all child routes. These get appended to an extra subroutes
	Middlewares []Middleware
}

func (*SubRouter) AddMiddleware

func (s *SubRouter) AddMiddleware(m ...Middleware)

func (*SubRouter) Route

func (s *SubRouter) Route(method, path string, handler http.Handler)

func (*SubRouter) RouteFiles

func (s *SubRouter) RouteFiles(path string, root http.FileSystem)

func (*SubRouter) SubRoute

func (s *SubRouter) SubRoute(path string) *SubRouter

Jump to

Keyboard shortcuts

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