otto

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 14 Imported by: 0

README

otto

Documentation

Index

Constants

View Source
const (
	HeaderAccept                        = "Accept"
	HeaderAcceptEncoding                = "Accept-Encoding"
	HeaderAllow                         = "Allow"
	HeaderAuthorization                 = "Authorization"
	HeaderContentDisposition            = "Content-Disposition"
	HeaderContentEncoding               = "Content-Encoding"
	HeaderContentLength                 = "Content-Length"
	HeaderContentType                   = "Content-Type"
	HeaderCookie                        = "Cookie"
	HeaderSetCookie                     = "Set-Cookie"
	HeaderIfModifiedSince               = "If-Modified-Since"
	HeaderLastModified                  = "Last-Modified"
	HeaderLocation                      = "Location"
	HeaderUpgrade                       = "Upgrade"
	HeaderVary                          = "Vary"
	HeaderWWWAuthenticate               = "WWW-Authenticate"
	HeaderXForwardedFor                 = "X-Forwarded-For"
	HeaderXForwardedProto               = "X-Forwarded-Proto"
	HeaderXForwardedProtocol            = "X-Forwarded-Protocol"
	HeaderXForwardedSsl                 = "X-Forwarded-Ssl"
	HeaderXUrlScheme                    = "X-Url-Scheme"
	HeaderXHTTPMethodOverride           = "X-HTTP-Method-Override"
	HeaderXRealIP                       = "X-Real-IP"
	HeaderXRequestID                    = "X-Request-ID"
	HeaderXRequestedWith                = "X-Requested-With"
	HeaderServer                        = "Server"
	HeaderOrigin                        = "Origin"
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"
	HeaderStrictTransportSecurity       = "Strict-Transport-Security"
	HeaderXContentTypeOptions           = "X-Content-Type-Options"
	HeaderXXSSProtection                = "X-XSS-Protection"
	HeaderXFrameOptions                 = "X-Frame-Options"
	HeaderContentSecurityPolicy         = "Content-Security-Policy"
	HeaderXCSRFToken                    = "X-CSRF-Token"
)

Variables

This section is empty.

Functions

func DefaultErrorHandler

func DefaultErrorHandler(code int, err error, ctx Context) error

DefaultErrorHandler will return the error as json

Types

type App

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

App holds on to options and the underlying router, the middleware, and more

func New

func New(opts Options) *App

New creates a new App

func (*App) Close

func (a *App) Close(err error) error

Close the application and try to shutdown gracefully

func (*App) Serve

func (a *App) Serve() error

Serve serves the application at the specified address and listening to OS interrupt and kill signals and will try to shutdown the app gracefully

type Context

type Context interface {
	JSON(int, interface{}) error
	HTML(int, string) error
	String(int, string) error
	Error(int, error) error
	NoContent() error
	Redirect(code int, location string) error
	Request() *http.Request
	Response() *Response
}

Context defines interface for otto Context

type ErrorHandler

type ErrorHandler func(int, error, Context) error

ErrorHandler defines the interface of a error handler

type ErrorHandlers

type ErrorHandlers struct {
	DefaultHandler ErrorHandler
	Handlers       map[int]ErrorHandler
}

ErrorHandlers holds a list of ErrorHandlers associated to status codes. It also holds a default ErrorHandler that will kick in if there is no other ErrorHandlers

func (ErrorHandlers) Get

func (e ErrorHandlers) Get(code int) ErrorHandler

Get will return a ErrorHandler that is associated with the provided status code, if none was found the DefaultHandler will be returned

type HTTPError

type HTTPError struct {
	Code int
	Err  error
}

HTTPError a typed error returned by handlers

func (HTTPError) Error

func (e HTTPError) Error() string

type HandlerFunc

type HandlerFunc func(Context) error

HandlerFunc defines the interface for r Route HandlerFunc

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

Middleware defines the inteface for a otto Middleware

type Options

type Options struct {
	Addr              string
	StrictSlash       bool
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
	// contains filtered or unexported fields
}

Options has all options that can be passed to App

func NewOptions

func NewOptions() Options

NewOptions creates new Options with default values

type Response

type Response struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Response that holds some information about the response

func (Response) Size

func (r Response) Size() int

Size returns the size of the content

func (*Response) Write

func (r *Response) Write(b []byte) (int, error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

WriteHeader writes the code to response writer and stores the status code

type Route

type Route struct {
	Path        string
	Method      string
	HandlerFunc HandlerFunc
	// contains filtered or unexported fields
}

Route has information about the route

func (Route) ServeHTTP

func (r Route) ServeHTTP(res http.ResponseWriter, req *http.Request)

type Router

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

Router handles all middleware, routes and error handlers

func NewRouter

func NewRouter(strictSlash bool) *Router

NewRouter creates a new Router with some default values

func (*Router) DELETE

func (r *Router) DELETE(p string, h HandlerFunc)

DELETE maps an "DELETE" request to the path and handler

func (*Router) GET

func (r *Router) GET(p string, h HandlerFunc)

GET maps an "GET" request to the path and handler

func (*Router) Group

func (r *Router) Group(p string) *Router

Group creates a new Router with a prefix for all routes

func (*Router) HEAD

func (r *Router) HEAD(p string, h HandlerFunc)

HEAD maps an "HEAD" request to the path and handler

func (*Router) OPTIONS

func (r *Router) OPTIONS(p string, h HandlerFunc)

OPTIONS maps an "OPTIONS" request to the path and handler

func (*Router) PATCH

func (r *Router) PATCH(p string, h HandlerFunc)

PATCH maps an "PATCH" request to the path and handler

func (*Router) POST

func (r *Router) POST(p string, h HandlerFunc)

POST maps an "POST" request to the path and handler

func (*Router) PUT

func (r *Router) PUT(p string, h HandlerFunc)

PUT maps an "PUT" request to the path and handler

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*Router) SetErrorHandlers

func (r *Router) SetErrorHandlers(eh map[int]ErrorHandler)

SetErrorHandlers associate error handlers with a status code

func (*Router) Static

func (r *Router) Static(p string, fs http.FileSystem)

Static serves static files like javascript, css and html files

func (*Router) Use

func (r *Router) Use(mf ...Middleware)

Use adds a Middleware to the router

type Routes

type Routes []*Route

Routes alias for slice of routes

func (Routes) Len

func (r Routes) Len() int

func (Routes) Less

func (r Routes) Less(i, j int) bool

func (Routes) Swap

func (r Routes) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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