web

package
v0.0.0-...-f1cee2f Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: MIT Imports: 28 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."}
	// ErrBadCaptcha is a captcha error
	ErrBadCaptcha = &Error{"bad_captcha", 400, "Bad CAPTCHA", "The provided CAPTCHA response does not match."}
	// ErrMissingPartRequest returns 400 if the request is missing some parts
	ErrMissingPartRequest = &Error{"missing_request", 400, "Bad request", "Request body is missing mandatory parts."}
	// ErrBadContentRequest if the request content is wrong
	ErrBadContentRequest = &Error{"bad_content", 400, "Bad content", "Request contains bad content"}
	// ErrAuth if not authenticated
	ErrAuth = &Error{"unauthorized", 401, "Unauthorized", "The request requires authorization"}
	// ErrCredentials if there are missing / wrong credentials
	ErrCredentials = &Error{"invalid_credentials", 401, "Invalid credentials", "Invalid username or password"}
	// ErrNotFound if file is not found
	ErrNotFound = &Error{"not_found", 404, "Not found", "The page you requested is not found"}
	// 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"}
	// ErrForbidden if request is forbidden to the user
	ErrForbidden = &Error{"forbidden", 403, "Forbidden", "Forbidden"}
	// ErrInternalServer if things go wrong on our side
	ErrInternalServer = &Error{"internal_server_error", 500, "Internal Server Error", "Something went wrong."}
	// ErrCouldNotFindTeam ...
	ErrCouldNotFindTeam = &Error{"could_find_team", 400, "Could not find slack team", "Could not find slack team"}
)

Functions

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.MySQL, q queue.Queue, b *bot.Bot) *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

type Errors

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

Errors is a list of errors

type Router

type Router struct {
	*httprouter.Router
}

Router handles the web requests routing

func New

func New(appC *AppContext) *Router

New creates a new router

func (*Router) Delete

func (r *Router) Delete(path string, handler http.Handler)

Delete handles DELETE requests

func (*Router) Get

func (r *Router) Get(path string, handler http.Handler)

Get handles GET requests

func (*Router) Post

func (r *Router) Post(path string, handler http.Handler)

Post handles POST requests

func (*Router) Put

func (r *Router) Put(path string, handler http.Handler)

Put handles PUt requests

func (*Router) Serve

func (r *Router) Serve()

Serve the routes based on configuration

Jump to

Keyboard shortcuts

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