http

package
v0.0.0-...-773e468 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error interface {
	error
	Status() int
}

Error embeds the standard error interface, along with a Status method that returns an HTTP status code.

type Handler

type Handler struct {
	*Server
	H HandlerFunc
}

Handler embeds the Server state and contains an H function that represents a handler for a certain HTTP route.

func (Handler) ServeHTTP

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

ServeHTTP satisfies the http.Handler interface.

type HandlerFunc

type HandlerFunc = func(s *Server, w http.ResponseWriter, r *http.Request) error

type Server

type Server struct {
	DB *db.Database

	HS     *http.Server
	Config config.Config
	// contains filtered or unexported fields
}

Server holds the DB connection, and configured router for the http package.

func Init

func Init(d *db.Database, c config.Config) *Server

Init takes in a Database and returns a new Server intialized with the default mux.Router and the database connection.

func (*Server) Start

func (s *Server) Start()

Start sets up router on the mux and starts the HTTP server.

type StatusError

type StatusError struct {
	Code int
	Err  error
}

StatusError represents an HTTP error, containing an HTTP status code and the error that caused it.

func (StatusError) Error

func (se StatusError) Error() string

Error satisifes the error interface.

func (StatusError) Status

func (se StatusError) Status() int

Status satisifies the Error interface.

Jump to

Keyboard shortcuts

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