Documentation ¶
Overview ¶
Package traffic - a Sinatra inspired regexp/pattern mux for Go.
Docs and examples are on github: https://github.com/pilu/traffic/
Index ¶
- Constants
- func ConfigFilePath() string
- func Env() string
- func GetVar(key string) interface{}
- func Host() string
- func Port() int
- func PublicPath() string
- func RenderTemplate(w ResponseWriter, templateName string, data ...interface{})
- func RootPath() string
- func SetHost(host string)
- func SetLogger(customLogger ILogger)
- func SetPort(port int)
- func SetVar(key string, value interface{})
- func TemplateFunc(name string, fn interface{})
- func TemplateFuncs(funcs map[string]interface{})
- func ViewsPath() string
- type ErrorHandlerFunc
- type HttpHandleFunc
- type HttpMethod
- type ILogger
- type LoggerMiddleware
- type Middleware
- type NextMiddlewareFunc
- type RenderFunc
- type Request
- type ResponseWriter
- type Route
- type Router
- func (router *Router) Add(method HttpMethod, path string, handlers ...HttpHandleFunc) *Route
- func (router *Router) AddBeforeFilter(beforeFilters ...HttpHandleFunc) *Router
- func (router *Router) Delete(path string, handlers ...HttpHandleFunc) *Route
- func (router *Router) Get(path string, handlers ...HttpHandleFunc) *Route
- func (router *Router) GetVar(key string) interface{}
- func (router Router) MiddlewareEnumerator() func() Middleware
- func (router *Router) Patch(path string, handlers ...HttpHandleFunc) *Route
- func (router *Router) Post(path string, handlers ...HttpHandleFunc) *Route
- func (router *Router) Put(path string, handlers ...HttpHandleFunc) *Route
- func (router *Router) Run()
- func (router *Router) ServeHTTP(httpResponseWriter http.ResponseWriter, httpRequest *http.Request)
- func (router *Router) SetVar(key string, value interface{})
- func (router *Router) Use(middleware Middleware)
- type RouterMiddleware
- type ShowErrorsMiddleware
- type StaticMiddleware
- type TemplateManager
Constants ¶
View Source
const ( EnvDevelopment = "development" DefaultViewsPath = "views" DefaultPublicPath = "public" DefaultConfigFile = "traffic.conf" DefaultPort = 7000 DefaultHost = "127.0.0.1" )
View Source
const TemplateExtension = ".tpl"
Variables ¶
This section is empty.
Functions ¶
func ConfigFilePath ¶
func ConfigFilePath() string
func PublicPath ¶
func PublicPath() string
func RenderTemplate ¶ added in v0.3.0
func RenderTemplate(w ResponseWriter, templateName string, data ...interface{})
func TemplateFunc ¶ added in v0.4.0
func TemplateFunc(name string, fn interface{})
func TemplateFuncs ¶ added in v0.4.0
func TemplateFuncs(funcs map[string]interface{})
Types ¶
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(ResponseWriter, *Request, interface{})
type HttpHandleFunc ¶
type HttpHandleFunc func(ResponseWriter, *Request)
type HttpMethod ¶
type HttpMethod string
type LoggerMiddleware ¶
type LoggerMiddleware struct {
// contains filtered or unexported fields
}
func (*LoggerMiddleware) ServeHTTP ¶
func (loggerMiddleware *LoggerMiddleware) ServeHTTP(w ResponseWriter, r *Request, next NextMiddlewareFunc) (ResponseWriter, *Request)
type Middleware ¶
type Middleware interface {
ServeHTTP(ResponseWriter, *Request, NextMiddlewareFunc) (ResponseWriter, *Request)
}
type NextMiddlewareFunc ¶
type NextMiddlewareFunc func() Middleware
type RenderFunc ¶
type RenderFunc func(w ResponseWriter, template string, data interface{})
type ResponseWriter ¶
type Route ¶
type Route struct { Path string PathRegexp *regexp.Regexp Handlers []HttpHandleFunc // contains filtered or unexported fields }
func NewRoute ¶
func NewRoute(path string, handlers ...HttpHandleFunc) *Route
func (*Route) AddBeforeFilter ¶
func (route *Route) AddBeforeFilter(beforeFilters ...HttpHandleFunc) *Route
type Router ¶
type Router struct { NotFoundHandler HttpHandleFunc ErrorHandler ErrorHandlerFunc // contains filtered or unexported fields }
func (*Router) Add ¶
func (router *Router) Add(method HttpMethod, path string, handlers ...HttpHandleFunc) *Route
func (*Router) AddBeforeFilter ¶
func (router *Router) AddBeforeFilter(beforeFilters ...HttpHandleFunc) *Router
func (*Router) Delete ¶
func (router *Router) Delete(path string, handlers ...HttpHandleFunc) *Route
func (Router) MiddlewareEnumerator ¶
func (router Router) MiddlewareEnumerator() func() Middleware
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(httpResponseWriter http.ResponseWriter, httpRequest *http.Request)
func (*Router) Use ¶ added in v0.4.0
func (router *Router) Use(middleware Middleware)
type RouterMiddleware ¶
type RouterMiddleware struct {
// contains filtered or unexported fields
}
func (*RouterMiddleware) ServeHTTP ¶
func (routerMiddleware *RouterMiddleware) ServeHTTP(w ResponseWriter, r *Request, next NextMiddlewareFunc) (ResponseWriter, *Request)
type ShowErrorsMiddleware ¶
type ShowErrorsMiddleware struct{}
func (ShowErrorsMiddleware) RenderError ¶
func (middleware ShowErrorsMiddleware) RenderError(w ResponseWriter, r *Request, err interface{}, stack []byte)
func (ShowErrorsMiddleware) ServeHTTP ¶
func (middleware ShowErrorsMiddleware) ServeHTTP(w ResponseWriter, r *Request, next NextMiddlewareFunc) (ResponseWriter, *Request)
type StaticMiddleware ¶
type StaticMiddleware struct {
// contains filtered or unexported fields
}
func NewStaticMiddleware ¶
func NewStaticMiddleware(publicPath string) *StaticMiddleware
func (*StaticMiddleware) ServeHTTP ¶
func (middleware *StaticMiddleware) ServeHTTP(w ResponseWriter, r *Request, next NextMiddlewareFunc) (ResponseWriter, *Request)
type TemplateManager ¶
type TemplateManager struct {
// contains filtered or unexported fields
}
func (*TemplateManager) Render ¶
func (t *TemplateManager) Render(w ResponseWriter, template string, data interface{})
func (*TemplateManager) RenderTemplateErrors ¶
func (t *TemplateManager) RenderTemplateErrors(w ResponseWriter, template string, data interface{})
Source Files ¶
Click to show internal directories.
Click to hide internal directories.