hador

package module
v0.0.0-...-eb3b190 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2016 License: Apache-2.0 Imports: 17 Imported by: 7

README

hador

Hodor Hador

Documentation

Overview

Package hador is a high preformance and easy to use web framework in Go.

example:

package main

import "github.com/Xuyuanp/hador"

func main() {
	h := hador.New()

	h.AddFilters(
		h.NewLogFilter(h.Logger),
	)

	h.Group("/v1", func(root hador.Router) {

		root.Get("/hello", func(ctx hador.Context) {
			ctx.Response.Write([]byte("hello"))
		}, f2)

		root.Get(`/hello/{name:\w+}`, func(ctx hador.Context) {
			name := ctx.Params().GetStringMust("name", "")
			ctx.Response.Write([]byte("hello " + name))
		}, f3, f4)

	}, f1)

	h.Get("/hello", func(ctx hador.Context) {
		ctx.Response.Write([]byte("hello"))
	}, f5)

	h.Run(":<your_port>")
}

GET /hello

LogFilter -> f5 -> handler -> f5 -> LogFilter

GET /v1/hello

LogFilter -> f1 -> f2 -> handler -> f2 -> f1 -> LogFilter

GET /v1/hello/alice

LogFilter -> f1 -> f3 -> f4 -> handler -> f4 -> f3 -> f1 -> LogFilter

Index

Constants

View Source
const (
	OPTIONS Method = "OPTIONS"
	GET            = "GET"
	HEAD           = "HEAD"
	POST           = "POST"
	PUT            = "PUT"
	DELETE         = "DELETE"
	TRACE          = "TRACE"
	CONNECT        = "CONNECT"
	PATCH          = "PATCH"
)

available methods.

View Source
const Version = "0.1.0"

Version is the current version number. Version format is '[major].[minor].[patch]'

Major: a large or potentially backward-incompatible API.
Minor: a new minor feature or a set of smaller features.
Patch: small bugfixed.

Variables

Methods is a list of all valid methods.

Functions

This section is empty.

Types

type BaseController

type BaseController struct {
}

BaseController provides an empty controller, returns Not Implemented status in any method.

func (*BaseController) Connect

func (c *BaseController) Connect(ctx *Context)

Connect implements ControllerInterface.

func (*BaseController) Delete

func (c *BaseController) Delete(ctx *Context)

Delete implements ControllerInterface.

func (*BaseController) DocConnect

func (c *BaseController) DocConnect(leaf *Leaf)

DocConnect implements ControllerInterface.

func (*BaseController) DocDelete

func (c *BaseController) DocDelete(leaf *Leaf)

DocDelete implements ControllerInterface.

func (*BaseController) DocGet

func (c *BaseController) DocGet(leaf *Leaf)

DocGet implements ControllerInterface.

func (*BaseController) DocHead

func (c *BaseController) DocHead(leaf *Leaf)

DocHead implements ControllerInterface.

func (*BaseController) DocOptions

func (c *BaseController) DocOptions(leaf *Leaf)

DocOptions implements ControllerInterface.

func (*BaseController) DocPatch

func (c *BaseController) DocPatch(leaf *Leaf)

DocPatch implements ControllerInterface.

func (*BaseController) DocPost

func (c *BaseController) DocPost(leaf *Leaf)

DocPost implements ControllerInterface.

func (*BaseController) DocPut

func (c *BaseController) DocPut(leaf *Leaf)

DocPut implements ControllerInterface.

func (*BaseController) DocTrace

func (c *BaseController) DocTrace(leaf *Leaf)

DocTrace implements ControllerInterface.

func (*BaseController) Get

func (c *BaseController) Get(ctx *Context)

Get implements ControllerInterface.

func (*BaseController) Head

func (c *BaseController) Head(ctx *Context)

Head implements ControllerInterface.

func (*BaseController) Options

func (c *BaseController) Options(ctx *Context)

Options implements ControllerInterface.

func (*BaseController) Patch

func (c *BaseController) Patch(ctx *Context)

Patch implements ControllerInterface.

func (*BaseController) Post

func (c *BaseController) Post(ctx *Context)

Post implements ControllerInterface.

func (*BaseController) Prepare

func (c *BaseController) Prepare(ctx *Context) bool

Prepare runs before other methods, and ends this request if returns false.

func (*BaseController) Put

func (c *BaseController) Put(ctx *Context)

Put implements ControllerInterface.

func (*BaseController) Trace

func (c *BaseController) Trace(ctx *Context)

Trace implements ControllerInterface.

type Beforer

type Beforer interface {
	Before(Filter) Beforer
	BeforeFunc(func(*Context, Handler)) Beforer
}

Beforer interface

type Context

type Context struct {
	Request  *http.Request
	Response ResponseWriter

	Logger Logger

	Err4XXHandler func(int, ...interface{})
	Err5XXHandler func(int, ...interface{})
	// contains filtered or unexported fields
}

Context struct

func (*Context) Delete

func (ctx *Context) Delete(key string) interface{}

Delete removes data from the context

func (*Context) Get

func (ctx *Context) Get(key string) interface{}

Get retrieves data from the context

func (*Context) GetOK

func (ctx *Context) GetOK(key string) (value interface{}, ok bool)

GetOK retrieves data from the context, and returns (nil, false) if no data

func (*Context) OnError

func (ctx *Context) OnError(status int, args ...interface{})

OnError handles http error by calling handler registered in SetErrorHandler methods. If no handler registered with this status and noting written yet, http.Error would be used.

func (*Context) Params

func (ctx *Context) Params() Params

Params returns params lazy-init

func (*Context) Redirect

func (ctx *Context) Redirect(url string, status int)

Redirect request.

func (*Context) RenderJSON

func (ctx *Context) RenderJSON(v interface{}, status ...int) error

RenderJSON renders v in JSON format and sets status if provided.

func (*Context) RenderJSONP

func (ctx *Context) RenderJSONP(v interface{}, callback string, status int) error

RenderJSONP method.

func (*Context) RenderPrettyJSON

func (ctx *Context) RenderPrettyJSON(v interface{}, status ...int) error

RenderPrettyJSON renders v in pretty JSON format and sets status if provided.

func (*Context) RenderPrettyXML

func (ctx *Context) RenderPrettyXML(v interface{}, status ...int) error

RenderPrettyXML renders v in pretty XML format and sets status if provided.

func (*Context) RenderXML

func (ctx *Context) RenderXML(v interface{}, status ...int) error

RenderXML renders v in XML format and sets status if provided.

func (*Context) ResolveJSON

func (ctx *Context) ResolveJSON(v interface{}) error

ResolveJSON resolve the request body into JSON format.

func (*Context) ResolveXML

func (ctx *Context) ResolveXML(v interface{}) error

ResolveXML resolve the request body into XML format.

func (*Context) Set

func (ctx *Context) Set(key string, value interface{})

Set saves data in the context

func (*Context) SetErrorHandler

func (ctx *Context) SetErrorHandler(status int, handler func(...interface{}))

SetErrorHandler sets custom handler for each http error

func (*Context) SetHeader

func (ctx *Context) SetHeader(key, value string)

SetHeader calls ctx.Response.Header().Set method

func (*Context) Write

func (ctx *Context) Write(p []byte) (n int, err error)

Write writes data into reponse by calling ctx.Response.Write method.

func (*Context) WriteHeader

func (ctx *Context) WriteHeader(status int)

WriteHeader writes header by calling ctx.Response.WriteHeader method

func (*Context) WriteStatus

func (ctx *Context) WriteStatus(p []byte, status ...int) (n int, err error)

WriteStatus writes data into response by calling ctx.Response.Write method, and sets status as provided, if multi status provided, the first one will be used, if no status provided, does noting.

func (*Context) WriteString

func (ctx *Context) WriteString(s string, status ...int) (n int, err error)

WriteString writes string into response by calling ctx.Write method.

type ControllerFilter

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

ControllerFilter filters controller by using controller.Prepare methods.

func (*ControllerFilter) Filter

func (cf *ControllerFilter) Filter(ctx *Context, next Handler)

Filter implements Filter interface.

type ControllerInterface

type ControllerInterface interface {
	// If Prepare method returns false, this request will be ended.
	Prepare(ctx *Context) bool

	Options(ctx *Context)
	Get(ctx *Context)
	Head(ctx *Context)
	Post(ctx *Context)
	Put(ctx *Context)
	Delete(ctx *Context)
	Trace(ctx *Context)
	Connect(ctx *Context)
	Patch(ctx *Context)

	DocOptions(leaf *Leaf)
	DocGet(leaf *Leaf)
	DocHead(leaf *Leaf)
	DocPost(leaf *Leaf)
	DocPut(leaf *Leaf)
	DocDelete(leaf *Leaf)
	DocTrace(leaf *Leaf)
	DocConnect(leaf *Leaf)
	DocPatch(leaf *Leaf)
}

ControllerInterface is definition of controller API.

type Filter

type Filter interface {
	Filter(ctx *Context, next Handler)
}

Filter interface

func Combine2Filters

func Combine2Filters(first, second Filter) Filter

Combine2Filters combines 2 Filters into a single Filter.

func CombineFilters

func CombineFilters(filters ...Filter) Filter

CombineFilters combines multi Filters into a single Filter.

type FilterChain

type FilterChain filterHandler

FilterChain struct combines multi Filters and Handler into a single Handler.

func NewFilterChain

func NewFilterChain(handler Handler, filters ...Filter) *FilterChain

NewFilterChain creates new FilterChain instance

func (*FilterChain) AddFilters

func (fc *FilterChain) AddFilters(filters ...Filter)

AddFilters adds all filters to chain

func (*FilterChain) Before

func (fc *FilterChain) Before(filter Filter) Beforer

Before implements Beforer interface

func (*FilterChain) BeforeFunc

func (fc *FilterChain) BeforeFunc(f func(*Context, Handler)) Beforer

BeforeFunc implements Beforer interface

func (*FilterChain) InsertBack

func (fc *FilterChain) InsertBack(filters ...Filter)

InsertBack inserts filters after self

func (*FilterChain) InsertFront

func (fc *FilterChain) InsertFront(filters ...Filter)

InsertFront insert filters before self

func (*FilterChain) Serve

func (fc *FilterChain) Serve(ctx *Context)

Serve implements Handler interface

type FilterFunc

type FilterFunc func(*Context, Handler)

FilterFunc as function

func NewLogFilter

func NewLogFilter(logger Logger) FilterFunc

NewLogFilter new a Filter to log each request details

func NewRecoveryFilter

func NewRecoveryFilter(logger Logger) FilterFunc

NewRecoveryFilter return a Filter to recover all unrecovered panic

func (FilterFunc) Filter

func (ff FilterFunc) Filter(ctx *Context, next Handler)

Filter implements Filter interface

type Grouper

type Grouper func(func(Router), ...Filter)

Grouper type is a group routing tool.

func (Grouper) Filters

func (g Grouper) Filters(fs ...Filter) Grouper

Filters creates a new Grouper appending filters.

func (Grouper) For

func (g Grouper) For(fn func(Router))

For calls Grouper function.

type HTTPError

type HTTPError int

HTTPError HTTP error type

func (HTTPError) Error

func (e HTTPError) Error() string

type Hador

type Hador struct {
	Router
	*FilterChain
	Logger Logger
	// contains filtered or unexported fields
}

Hador struct

func Default

func Default() *Hador

Default creates Hador instance with default filters(LogFilter, RecoveryFilter)

func New

func New() *Hador

New creates new Hador instance

func (*Hador) AddFilters

func (h *Hador) AddFilters(filters ...Filter) *Hador

AddFilters reuses FilterChain's AddFilters method and returns self

func (*Hador) Run

func (h *Hador) Run(addr string) error

Run starts serving HTTP request

func (*Hador) RunExitOnError

func (h *Hador) RunExitOnError(addr string)

RunExitOnError starts serving HTTP request and exit app if any error occurs.

func (*Hador) RunTLS

func (h *Hador) RunTLS(addr, sertFile, keyFile string) error

RunTLS starts serving HTTPS request.

func (*Hador) RunTLSExitOnError

func (h *Hador) RunTLSExitOnError(addr, sertFile, keyFile string)

RunTLSExitOnError starts serving HTTPS request and exit app if any error occurs.

func (*Hador) Serve

func (h *Hador) Serve(ctx *Context)

Serve implements Handler interface

func (*Hador) ServeHTTP

func (h *Hador) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Hador) Swagger

func (h *Hador) Swagger(config SwaggerConfig) *Leaf

Swagger setups swagger config, returns json API path Leaf

func (*Hador) SwaggerDocument

func (h *Hador) SwaggerDocument() *swagger.Document

SwaggerDocument returns swagger.Document of this Hador.

func (*Hador) SwaggerHandler

func (h *Hador) SwaggerHandler() Handler

SwaggerHandler returns swagger json api handler

type Handler

type Handler interface {
	Serve(*Context)
}

Handler interface

func Data

func Data(v interface{}) Handler

Data handler

func JSON

func JSON(v interface{}) Handler

JSON handler

func OK

func OK(msg string) Handler

OK default handler

func Status

func Status(status int) Handler

Status handler

func XML

func XML(v interface{}) Handler

XML handler

type HandlerFunc

type HandlerFunc func(ctx *Context)

HandlerFunc is Handle as function

func Wrap

func Wrap(handler http.Handler) HandlerFunc

Wrap wraps http.Handler to Handler

func WrapFunc

func WrapFunc(hf func(http.ResponseWriter, *http.Request)) HandlerFunc

WrapFunc wraps http.HandlerFunc to HandlerFunc

func (HandlerFunc) Serve

func (hf HandlerFunc) Serve(ctx *Context)

Serve implements Handler interface by calling HandlerFunc function

type HandlerSetter

type HandlerSetter func(handler interface{}, filters ...Filter) *Leaf

HandlerSetter easy way to set Handler for a route.

func (HandlerSetter) Filters

func (hs HandlerSetter) Filters(filters ...Filter) HandlerSetter

Filters creates a new HandlerSetter to append filters.

func (HandlerSetter) Handler

func (hs HandlerSetter) Handler(handler interface{}, filters ...Filter) *Leaf

Handler calls HandlerSetter function.

type Leaf

type Leaf struct {
	*FilterChain

	DocIgnored bool
	// contains filtered or unexported fields
}

Leaf struct

func NewLeaf

func NewLeaf(parent *node, method Method, handler Handler) *Leaf

NewLeaf creates new Leaf instance

func (*Leaf) AddFilters

func (l *Leaf) AddFilters(filters ...Filter) *Leaf

AddFilters add filters into FilterChain

func (*Leaf) DocIgnore

func (l *Leaf) DocIgnore(ignored bool) *Leaf

DocIgnore sets if this route would be ignored in document

func (*Leaf) Handler

func (l *Leaf) Handler() Handler

Handler returns handler of Leaf

func (*Leaf) Method

func (l *Leaf) Method() Method

Method returns method of Leaf

func (*Leaf) Path

func (l *Leaf) Path() string

Path returns the full path from root to the parent node

func (*Leaf) SwaggerOperation

func (l *Leaf) SwaggerOperation() *swagger.Operation

SwaggerOperation returns swagger Operation of this route.

type Logger

type Logger interface {
	Debug(string, ...interface{})
	Info(string, ...interface{})
	Warning(string, ...interface{})
	Error(string, ...interface{})
	Critical(string, ...interface{})
}

Logger interface

type Method

type Method string

Method is HTTP method.

func (Method) String

func (m Method) String() string

type MethodSetter

type MethodSetter func(method Method) PatternSetter

MethodSetter easy way to set Method for a route.

func (MethodSetter) Connect

func (ms MethodSetter) Connect() PatternSetter

Connect short for Method(CONNECT)

func (MethodSetter) Delete

func (ms MethodSetter) Delete() PatternSetter

Delete short for Method(DELETE)

func (MethodSetter) Get

func (ms MethodSetter) Get() PatternSetter

Get short for Method(GET)

func (MethodSetter) Group

func (ms MethodSetter) Group(root string) Grouper

Group creates a new Grouper with root.

func (MethodSetter) Head

func (ms MethodSetter) Head() PatternSetter

Head short for Method(HEAD)

func (MethodSetter) Method

func (ms MethodSetter) Method(method Method) PatternSetter

Method calls MethodSetter function.

func (MethodSetter) Options

func (ms MethodSetter) Options() PatternSetter

Options short for Method(OPTIONS)

func (MethodSetter) Patch

func (ms MethodSetter) Patch() PatternSetter

Patch short for Method(PATCH)

func (MethodSetter) Post

func (ms MethodSetter) Post() PatternSetter

Post short for Method(POST)

func (MethodSetter) Put

func (ms MethodSetter) Put() PatternSetter

Put short for Method(PUT)

func (MethodSetter) Trace

func (ms MethodSetter) Trace() PatternSetter

Trace short for Method(TRACE)

type Middleware

type Middleware func(next Handler) Handler

Middleware is another type of Filter.

func (Middleware) Filter

func (mw Middleware) Filter(ctx *Context, next Handler)

Filter implements Filter interface.

type Param

type Param struct {
	Key   string
	Value string
}

Param is Params' entry

type Params

type Params []Param

Params is a wrapper of map[string]string to handle the params in regexp pattern. If the handler's URL pattern is "/api/(?P<name>\w+)/{age:\d+}" and the request URL is "/api/jack/12", the Params will be { "name": "jack", "age": "12" }. Using `hodor.GetParams(req)` to get the Params. type Params map[string]string

func (Params) GetBool

func (params Params) GetBool(key string) (bool, error)

GetBool gets params with key in boolean format

func (Params) GetBoolMust

func (params Params) GetBoolMust(key string, def bool) bool

GetBoolMust gets params with key in boolean format

func (Params) GetFloat32

func (params Params) GetFloat32(key string) (float32, error)

GetFloat32 gets params with key in float32 format

func (Params) GetFloat32Must

func (params Params) GetFloat32Must(key string, def float32) float32

GetFloat32Must gets params with key in float32 format

func (Params) GetFloat64

func (params Params) GetFloat64(key string) (float64, error)

GetFloat64 gets params with key in float64 format

func (Params) GetFloat64Must

func (params Params) GetFloat64Must(key string, def float64) float64

GetFloat64Must gets params with key in float64 format

func (Params) GetInt

func (params Params) GetInt(key string) (int, error)

GetInt method does the same work as GetString, but converts the string into integer. If the param is not a valid integer, an err will be returned.

func (Params) GetInt16

func (params Params) GetInt16(key string) (int16, error)

GetInt16 gets params with key in int16 format

func (Params) GetInt16Must

func (params Params) GetInt16Must(key string, def int16) int16

GetInt16Must gets params with key in int16 format

func (Params) GetInt32

func (params Params) GetInt32(key string) (int32, error)

GetInt32 gets params with key in int32 format

func (Params) GetInt32Must

func (params Params) GetInt32Must(key string, def int32) int32

GetInt32Must gets params with key in int32 format

func (Params) GetInt64

func (params Params) GetInt64(key string) (int64, error)

GetInt64 gets params with key in int64 format

func (Params) GetInt64Must

func (params Params) GetInt64Must(key string, def int64) int64

GetInt64Must gets params with key in int64 format

func (Params) GetInt8

func (params Params) GetInt8(key string) (int8, error)

GetInt8 gets params with key in int8 format

func (Params) GetInt8Must

func (params Params) GetInt8Must(key string, def int8) int8

GetInt8Must gets params with key in int8 format

func (Params) GetIntMust

func (params Params) GetIntMust(key string, def int) int

GetIntMust method does the same work as GetStringMust, but converts the string into integer. If the param is not a valid integer, the default value will be returned.

func (Params) GetString

func (params Params) GetString(key string) (string, error)

GetString method returns the param named `key` as string type.

func (Params) GetStringMust

func (params Params) GetStringMust(key string, def string) string

GetStringMust method returns the param named `key` as string type. If no param with the provided name, the default value will be returned.

func (Params) GetUint

func (params Params) GetUint(key string) (uint, error)

GetUint gets params with key in uint format

func (Params) GetUint16

func (params Params) GetUint16(key string) (uint16, error)

GetUint16 gets params with key in uint16 format

func (Params) GetUint16Must

func (params Params) GetUint16Must(key string, def uint16) uint16

GetUint16Must gets params with key in uint16 format

func (Params) GetUint32

func (params Params) GetUint32(key string) (uint32, error)

GetUint32 gets params with key in uint32 format

func (Params) GetUint32Must

func (params Params) GetUint32Must(key string, def uint32) uint32

GetUint32Must gets params with key in uint32 format

func (Params) GetUint64

func (params Params) GetUint64(key string) (uint64, error)

GetUint64 gets params with key in uint64 format

func (Params) GetUint64Must

func (params Params) GetUint64Must(key string, def uint64) uint64

GetUint64Must gets params with key in uint64 format

func (Params) GetUint8

func (params Params) GetUint8(key string) (uint8, error)

GetUint8 gets params with key in uint8 format

func (Params) GetUint8Must

func (params Params) GetUint8Must(key string, def uint8) uint8

GetUint8Must gets params with key in uint8 format

func (Params) GetUintMust

func (params Params) GetUintMust(key string, def uint) uint

GetUintMust gets params with key in uint format

type PatternSetter

type PatternSetter func(pattern string) HandlerSetter

PatternSetter easy way to set Path for a route.

func (PatternSetter) Pattern

func (ps PatternSetter) Pattern(pattern string) HandlerSetter

Pattern calls Pattern function.

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	// Status returns the status code of the response or 0 if the response has not been written.
	Status() int

	WriteString(string) (int, error)

	// Written returns whether or not the ResponseWriter has been written.
	Written() bool
	// Size returns the size of the response body.
	Size() int
	// Before allows for a function to be called before the ResponseWriter has been written to. This is
	// useful for setting headers or any other operations that must happen before a response has been written.
	Before(func(ResponseWriter))
}

ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) ResponseWriter

NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter

type Router

type Router interface {
	Route() MethodSetter

	Options(pattern string, h interface{}, filters ...Filter) *Leaf
	Get(pattern string, h interface{}, filters ...Filter) *Leaf
	Head(pattern string, h interface{}, filters ...Filter) *Leaf
	Post(pattern string, h interface{}, filters ...Filter) *Leaf
	Put(pattern string, h interface{}, filters ...Filter) *Leaf
	Delete(pattern string, h interface{}, filters ...Filter) *Leaf
	Trace(pattern string, h interface{}, filters ...Filter) *Leaf
	Connect(pattern string, h interface{}, filters ...Filter) *Leaf
	Patch(pattern string, h interface{}, filters ...Filter) *Leaf

	// Any routes doesn't support swagger API, always returns nil.
	Any(pattern string, h interface{}, filters ...Filter) *Leaf

	// Be carefull! All requests match this pattern would be processed by the provided
	// controller instance, no new ControllerInterface implemented instance would be
	// created. If you want to share data in your controller, please make sure it is
	// goroutine-safe.
	AddController(pattern string, controller ControllerInterface, filters ...Filter)

	AddRoute(method Method, pattern string, h interface{}, filters ...Filter) *Leaf

	Group(pattern string, fn func(Router), filters ...Filter)
}

Router interface

type RouterFunc

type RouterFunc func(method Method, pattern string, handler interface{}, filters ...Filter) *Leaf

RouterFunc is a function type implemented Router interface.

func (RouterFunc) AddController

func (r RouterFunc) AddController(pattern string, controller ControllerInterface, filters ...Filter)

AddController adds routes of all methods by calling controller's matched method.

func (RouterFunc) AddRoute

func (r RouterFunc) AddRoute(method Method, pattern string, handler interface{}, filters ...Filter) *Leaf

AddRoute calls RouterFunc function. It is the most important method of RouterFunc. All other methods call this method finally.

func (RouterFunc) Any

func (r RouterFunc) Any(pattern string, handler interface{}, filters ...Filter) *Leaf

Any adds a new route binded with all method.

func (RouterFunc) Connect

func (r RouterFunc) Connect(pattern string, handler interface{}, filters ...Filter) *Leaf

Connect adds a new route binded with CONNECT method.

func (RouterFunc) Delete

func (r RouterFunc) Delete(pattern string, handler interface{}, filters ...Filter) *Leaf

Delete adds a new route binded with DELETE method.

func (RouterFunc) Get

func (r RouterFunc) Get(pattern string, handler interface{}, filters ...Filter) *Leaf

Get adds a new route binded with GET method.

func (RouterFunc) Group

func (r RouterFunc) Group(pattern string, fn func(Router), filters ...Filter)

Group adds multi routes one time.

func (RouterFunc) Head

func (r RouterFunc) Head(pattern string, handler interface{}, filters ...Filter) *Leaf

Head adds a new route binded with HEAD method.

func (RouterFunc) Options

func (r RouterFunc) Options(pattern string, handler interface{}, filters ...Filter) *Leaf

Options adds a new route binded with OPTIONS method.

func (RouterFunc) Patch

func (r RouterFunc) Patch(pattern string, handler interface{}, filters ...Filter) *Leaf

Patch adds a new route binded with Patch method.

func (RouterFunc) Post

func (r RouterFunc) Post(pattern string, handler interface{}, filters ...Filter) *Leaf

Post adds a new route binded with POST method.

func (RouterFunc) Put

func (r RouterFunc) Put(pattern string, handler interface{}, filters ...Filter) *Leaf

Put adds a new route binded with PUT method.

func (RouterFunc) Route

func (r RouterFunc) Route() MethodSetter

Route returns a setter-chain to add a new route step-by-step.

func (RouterFunc) Trace

func (r RouterFunc) Trace(pattern string, handler interface{}, filters ...Filter) *Leaf

Trace adds a new route binded with TRACE method.

type Static

type Static struct {
	Prefix    string
	IndexFile string
	Dir       http.FileSystem
}

Static struct

func NewStatic

func NewStatic(dir http.FileSystem) *Static

NewStatic creates new Static instance

func (*Static) Filter

func (s *Static) Filter(ctx *Context, next Handler)

Filter serves all static file request

type SwaggerConfig

type SwaggerConfig struct {
	// UIFilePath is the location of folder containing swagger-ui index.html file. e.g. swagger-ui/dist
	UIFilePath string

	// UIPrefx is the path where swagger-ui whill be served. e.g. /apidocs
	UIPrefix string

	// APIPath is the path where JSON API is available. e.g. /apidocs.json
	APIPath string

	// SelfDocEnabled enable the swagger-ui path API in doc. False on default.
	SelfDocEnabled bool
}

SwaggerConfig struct, mirror of swagger.Config

Directories

Path Synopsis
Package swagger provides swagger specification models
Package swagger provides swagger specification models

Jump to

Keyboard shortcuts

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