web

package
v0.0.0-...-091106e Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadRequest is a generic bad request
	ErrBadRequest = &Error{"bad_request", 400, "Bad request", "Request body is not well-formed. It must be JSON."}
	// ErrMissingPartRequest returns 400 if the request is missing some parts
	ErrMissingPartRequest = &Error{"missing_request", 400, "Bad request", "Request body is missing mandatory parts."}
	// ErrAuth if not authenticated
	ErrAuth = &Error{"unauthorized", 401, "Unauthorized", "The request requires authorization"}
	// ErrPermission if not authenticated
	ErrPermission = &Error{"forbidden", 403, "Forbidden", "The request requires the right permissions"}
	// ErrCredentials if there are missing / wrong credentials
	ErrCredentials = &Error{"invalid_credentials", 401, "Invalid credentials", "Invalid username or password"}
	// ErrNotAcceptable wrong accept header
	ErrNotAcceptable = &Error{"not_acceptable", 406, "Not Acceptable", "Accept header must be set to 'application/json'."}
	// ErrUnsupportedMediaType wrong media type
	ErrUnsupportedMediaType = &Error{"unsupported_media_type", 415, "Unsupported Media Type", "Content-Type header must be set to: 'application/json'."}
	// ErrCSRF missing CSRF cookie or parameter
	ErrCSRF = &Error{"forbidden", 403, "Forbidden", "Issue with CSRF code"}
	// ErrInternalServer if things go wrong on our side
	ErrInternalServer = &Error{"internal_server_error", 500, "Internal Server Error", "Something went wrong."}
)

Functions

func GetTLSConfig

func GetTLSConfig() (config *tls.Config, err error)

GetTLSConfig ...

func WriteError

func WriteError(w http.ResponseWriter, err *Error)

WriteError writes an error to the reply

Types

type AppContext

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

AppContext holds the web context for the handlers

func NewContext

func NewContext(r *repo.Repo) *AppContext

NewContext creates a new context

type Error

type Error struct {
	ID     string `json:"id"`
	Status int    `json:"status"`
	Title  string `json:"title"`
	Detail string `json:"detail"`
}

Error holds the info about a web error

func (*Error) Error

func (e *Error) Error() string

type Errors

type Errors struct {
	Errors []*Error `json:"errors"`
}

Errors is a list of errors

type Router

type Router struct {
	*httprouter.Router
	// contains filtered or unexported fields
}

Router handles the web requests routing

func New

func New(appC *AppContext, pubPath string) *Router

New creates a new router

func (*Router) Delete

func (r *Router) Delete(path string, requires []domain.UserType, handler http.Handler)

Delete handles DELETE requests

func (*Router) Get

func (r *Router) Get(path string, requires []domain.UserType, handler http.Handler)

Get handles GET requests

func (*Router) Post

func (r *Router) Post(path string, requires []domain.UserType, handler http.Handler)

Post handles POST requests

func (*Router) Put

func (r *Router) Put(path string, requires []domain.UserType, handler http.Handler)

Put handles PUT requests

func (*Router) Serve

func (r *Router) Serve()

Serve - creates the relevant listeners

func (*Router) ServeGzipFiles

func (r *Router) ServeGzipFiles(path string, root http.FileSystem)

ServeGzipFiles ...

Jump to

Keyboard shortcuts

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