Documentation ¶
Index ¶
- Constants
- Variables
- type Application
- func (app *Application) DELETE(path string, h Handler, opts ...RouteOption)
- func (app *Application) GET(path string, h Handler, opts ...RouteOption)
- func (app *Application) PATCH(path string, h Handler, opts ...RouteOption)
- func (app *Application) POST(path string, h Handler, opts ...RouteOption)
- func (app *Application) PUT(path string, h Handler, opts ...RouteOption)
- func (app *Application) Run() error
- type CORSConfig
- type Decoder
- type Encoder
- type Handler
- type Logger
- type Middleware
- type Option
- type OptionFn
- type Request
- type RouteOption
- type RouteOptionFn
Constants ¶
const ( HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderContentType = "Content-Type" HeaderOrigin = "Origin" HeaderVary = "Vary" )
Headers
Variables ¶
var DefaultCORSConfig = CORSConfig{ AllowOrigins: []string{"*"}, AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete}, }
DefaultCORSConfig is the default configuration for the WithCORS middleware.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application is a web application.
func Default ¶
func Default() *Application
Default returns an Application with a default set of configurations.
func (*Application) DELETE ¶
func (app *Application) DELETE(path string, h Handler, opts ...RouteOption)
DELETE registers a new DELETE route for a path with handler.
func (*Application) GET ¶
func (app *Application) GET(path string, h Handler, opts ...RouteOption)
GET registers a new GET route for a path with handler.
func (*Application) PATCH ¶
func (app *Application) PATCH(path string, h Handler, opts ...RouteOption)
PATCH registers a new PATCH route for a path with handler.
func (*Application) POST ¶
func (app *Application) POST(path string, h Handler, opts ...RouteOption)
POST registers a new POST route for a path with handler.
func (*Application) PUT ¶
func (app *Application) PUT(path string, h Handler, opts ...RouteOption)
PUT registers a new PUT route for a path with handler.
type CORSConfig ¶
type CORSConfig struct { AllowOrigins []string AllowMethods []string AllowHeaders []string AllowCredentials bool MaxAge int }
CORSConfig defines the config for WithCORS middleware.
type Decoder ¶
type Decoder interface { // Decode decodes a request to a struct. req.PostForm is called in advanced. Decode(obj interface{}, req *http.Request) error }
Decoder defines a request decoder.
type Encoder ¶
type Encoder interface { // Encode encodes obj and writes to http.ResponseWriter. Encode(w http.ResponseWriter, obj interface{}) error }
Encoder define a request decoder.
type Logger ¶
type Logger interface {
// Println prints out logs like fmt.Println.
Println(...interface{})
}
Logger defines a Logger.
type Middleware ¶
Middleware defines a middleware to provide additional logic.
func WithCORS ¶
func WithCORS(cfg CORSConfig) Middleware
WithCORS returns a middleware to support Cross-Origin Resource Sharing.
func (Middleware) ApplyRoute ¶
func (m Middleware) ApplyRoute(r *route)
ApplyRoute implements RouteOption.
type Option ¶
type Option interface {
Apply(app *Application)
}
Option defines an application Option.
type OptionFn ¶
type OptionFn func(app *Application)
OptionFn defines a function that implements Option
func WithLogger ¶
WithLogger specifies a custom Logger for tha application.
type Request ¶
type Request interface { // HTTPRequest returns the http.Request. HTTPRequest() *http.Request // Decode decodes the request to an object. Decode(obj interface{}) error // ResponseHeader returns the header map that will be sent. ResponseHeader() http.Header }
Request defines a HTTP request.
type RouteOption ¶
type RouteOption interface {
ApplyRoute(r *route)
}
RouteOption defines an option to customize a route.
type RouteOptionFn ¶
type RouteOptionFn func(r *route)
RouteOptionFn defines a function implementation of RouteOption.
func WithDecoder ¶
func WithDecoder(d Decoder) RouteOptionFn
WithDecoder specifies the decoder which will be used.
func WithRecovery ¶
func WithRecovery() RouteOptionFn
WithRecovery returns a middleware which recovers from panics.
func (RouteOptionFn) Apply ¶
func (fn RouteOptionFn) Apply(app *Application)
Apply implements Option.
func (RouteOptionFn) ApplyRoute ¶
func (fn RouteOptionFn) ApplyRoute(r *route)
ApplyRoute implements RouteOption.