Documentation ¶
Index ¶
- Constants
- Variables
- type Context
- type Engine
- func (e *Engine) CreateContext(w http.ResponseWriter, r *http.Request, params Params) Context
- func (e *Engine) DELETE(path string, f HandlerFunc)
- func (e *Engine) DefaultHTTPErrorHandler(err error, c Context)
- func (e *Engine) Find(method, path string, c Context) (valid bool)
- func (e *Engine) GET(path string, f HandlerFunc)
- func (e *Engine) HEAD(path string, f HandlerFunc)
- func (e *Engine) Handle(method, path string, handler HandlerFunc)
- func (e *Engine) Listen() (net.Listener, error)
- func (e *Engine) Lookup(method, path string) (HandlerFunc, Params)
- func (e *Engine) NewContext(w http.ResponseWriter, r *http.Request) Context
- func (e *Engine) OPTIONS(path string, f HandlerFunc)
- func (e *Engine) PATCH(path string, f HandlerFunc)
- func (e *Engine) POST(path string, f HandlerFunc)
- func (e *Engine) PUT(path string, f HandlerFunc)
- func (e *Engine) ReUseContext(c Context)
- func (e *Engine) Serve(ctx context.Context) error
- func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (e *Engine) Shutdown(ctx context.Context) error
- func (e *Engine) Start(ctx context.Context) error
- func (e *Engine) UseMiddleWare(middleware ...MiddlewareFunc)
- type HTTPError
- type HandlerFunc
- type Map
- type MiddlewareFunc
- type Params
- type Response
- type Vars
Constants ¶
const ( DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PUT = "PUT" )
HTTP methods
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(status.UnsupportedMediaType) ErrNotFound = NewHTTPError(status.NotFound) ErrForbidden = NewHTTPError(status.Forbidden) ErrMethodNotAllowed = NewHTTPError(status.MethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(status.RequestEntityTooLarge) ErrInternalServer = NewHTTPError(status.InternalServerError) ErrValidatorNotRegistered = errors.New("Validator not registered") ErrRendererNotRegistered = errors.New("Renderer not registered") ErrInvalidRedirectCode = errors.New("Invalid redirect status code") ErrCookieNotFound = errors.New("Cookie not found") )
Errors
var ( // NotFoundHandler run if not match registerd method and path. NotFoundHandler = func(c Context) error { return ErrNotFound } // MethodNotAllowedHandler run if not match registerd method. MethodNotAllowedHandler = func(c Context) error { return ErrMethodNotAllowed } )
var ( LogDir = "log" LogName = "fin_log" )
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface { Path() string SetPath(string) Request() *http.Request SetRequest(*http.Request) Response() *Response QueryParam(string) string QueryParams() url.Values QueryString() string Params() httprouter.Params FormValue(string) string FormParams() (url.Values, error) Cookie(string) (*http.Cookie, error) SetCookie(*http.Cookie) Cookies() []*http.Cookie Handler() HandlerFunc SetHandler(HandlerFunc) Error(error) Get(interface{}) interface{} Set(interface{}, interface{}) NoContent(int) error Redirect(code int, url string) error Logger() *zap.Logger Render(tmpl string, vars xslate.Vars) error SetContentType(code int, contentType string) JSON(code int, i interface{}) error XML(code int, i interface{}) error String(code int, content string) error }
type Engine ¶
type Engine struct { *zap.Logger *xslate.Xslate Port int Server *http.Server HTTPErrorHandler func(error, Context) // contains filtered or unexported fields }
Engine is context for this application
func (*Engine) CreateContext ¶
func (*Engine) DELETE ¶
func (e *Engine) DELETE(path string, f HandlerFunc)
DELETE registers a new DELETE route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler render error message to response
func (*Engine) Find ¶
Find lookup a handler registered for method and path. It also parses URL for path parameters and load them into context.
func (*Engine) GET ¶
func (e *Engine) GET(path string, f HandlerFunc)
GET registers a new GET route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) HEAD ¶
func (e *Engine) HEAD(path string, f HandlerFunc)
HEAD registers a new HEAD route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) Handle ¶
func (e *Engine) Handle(method, path string, handler HandlerFunc)
Handle registers a your specified a path and method into httprouter with optional handler-level middleware.
func (*Engine) Lookup ¶
func (e *Engine) Lookup(method, path string) (HandlerFunc, Params)
Lookup a handler registerd for method and path. It returns path parameters and HandlerFunc or nil HandlerFunc
func (*Engine) NewContext ¶
NewContext returns a Context instance.
func (*Engine) OPTIONS ¶
func (e *Engine) OPTIONS(path string, f HandlerFunc)
OPTIONS registers a new OPTIONS route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) PATCH ¶
func (e *Engine) PATCH(path string, f HandlerFunc)
PATCH registers a new PATCH route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) POST ¶
func (e *Engine) POST(path string, f HandlerFunc)
POST registers a new POST route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) PUT ¶
func (e *Engine) PUT(path string, f HandlerFunc)
PUT registers a new PUT route for a path with matching handler into the httprouter with optional handler-level middleware.
func (*Engine) ReUseContext ¶
func (*Engine) UseMiddleWare ¶
func (e *Engine) UseMiddleWare(middleware ...MiddlewareFunc)
UseMiddleWare registers middleware handlers before run registered matching handler.
type HTTPError ¶
HTTPError represents an error that occurred while handling a request.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
type HandlerFunc ¶
HandlerFunc defines a function to server HTTP requests.
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
MiddlewareFunc defines a function to server HTTP requests.
type Response ¶
type Response struct { Writer http.ResponseWriter Size int64 Status int Committed bool }
func NewResponse ¶
func NewResponse(w http.ResponseWriter) (r *Response)
NewResponse creates a new instance of Response.
func (*Response) CloseNotify ¶
CloseNotify implements the http.CloseNotifier interface to allow detecting when the underlying connection has gone away. This mechanism can be used to cancel long operations on the server if the client has disconnected before the response is ready. See http.CloseNotifier(https://golang.org/pkg/net/http/#CloseNotifier)
func (*Response) Flush ¶
func (r *Response) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)
func (*Response) Header ¶
Header returns the header map for the writer that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example) To suppress implicit response headers, set their value to nil. Example: https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
func (*Response) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See http.Hijacker(https://golang.org/pkg/net/http/#Hijacker)