httpserver

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: AGPL-3.0 Imports: 24 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 ReverseStringSlice

func ReverseStringSlice(s []string) []string

Types

type Config

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

func (*Config) Validate

func (c *Config) Validate() error

type HTTPService

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

func New added in v0.1.10

func New(
	config *Config,
	db letterbox.Datastore,
	log logger.Logger,
	info *letterbox.Info,
	hasher letterbox.ArgonHasher,
	badActors *badactor.Studio,
	domains *letterbox.DomainService,
	mailboxes *letterbox.MailboxService,
	messages *letterbox.MessageService,
	users *letterbox.UserService,
	statsSummary StatsSummarizer,
) *HTTPService

func (*HTTPService) Name

func (s *HTTPService) Name() string

func (*HTTPService) Start

func (s *HTTPService) Start() error

func (*HTTPService) Stop

func (s *HTTPService) Stop() error

type Handler added in v0.1.10

type Handler struct {
	Handler HandlerFunc
	// contains filtered or unexported fields
}

Handler wraps a HandlerFunc with a logger to provide consistent logging.

func (Handler) ServeHTTP added in v0.1.10

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

ServeHTTP will call the wrapped HandlerFunc. If the returned interface{} is non-nil, it is to be the response body. If error is non-nil, an HTTP error message is to be returned. See getStatusCodeForError to determine how specific errors are mapped to HTTP status codes.

type HandlerFunc added in v0.1.10

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

HandlerFunc describes our custom HTTP handler definition. It's similar to a standard http.HandlerFunc, except it also allows returning an interface{} and an error.

type Middleware

type Middleware func(http.Handler) http.Handler

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 StatsSummarizer added in v0.1.14

type StatsSummarizer interface {
	GetStats(mailbox *letterbox.Mailbox) ([]letterbox.DomainStat, error)
}

type SubRouter

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

func NewRouter added in v0.1.10

func NewRouter(log logger.Logger) *SubRouter

func (*SubRouter) Handler added in v0.1.10

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

func (*SubRouter) Route

func (s *SubRouter) Route(method, path string, endpoint HandlerFunc)

func (*SubRouter) RouteFiles

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

func (*SubRouter) ServeHTTP added in v0.1.10

func (s *SubRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*SubRouter) SubRoute

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

func (*SubRouter) Use added in v0.1.10

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

func (*SubRouter) UsePerRoute added in v0.1.10

func (s *SubRouter) UsePerRoute(m ...PerRouteMiddleware)

Jump to

Keyboard shortcuts

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