Documentation ¶
Index ¶
- Constants
- Variables
- func MethodNotAllowedHandler(ctx *Context) error
- func NotFoundHandler(ctx *Context) error
- type Context
- func (ctx *Context) Error(code int, error string)
- func (ctx *Context) FormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (ctx *Context) Get(key string) interface{}
- func (ctx *Context) GetCookie(name string) string
- func (ctx *Context) Gets() map[string]interface{}
- func (ctx *Context) Init(w http.ResponseWriter, r *http.Request)
- func (ctx *Context) JSON(code, flag int, msg string, data interface{}) error
- func (ctx *Context) JSONP(code int, callback string, data interface{}) error
- func (ctx *Context) Method() string
- func (ctx *Context) Next()
- func (ctx *Context) Param(key string) string
- func (ctx *Context) Params() url.Values
- func (ctx *Context) Path() string
- func (ctx *Context) Redirect(code int, url string)
- func (ctx *Context) Referer() string
- func (ctx *Context) Render(code int, tplname string) error
- func (ctx *Context) SaveFile(name, saveDir string) (string, error)
- func (ctx *Context) Set(key string, val interface{})
- func (ctx *Context) SetCookie(name, value string)
- func (ctx *Context) Status() int
- func (ctx *Context) Text(code int, body string) error
- func (ctx *Context) UserAgent() string
- func (ctx *Context) Write(data []byte) (n int, err error)
- type HandlerFunc
- type SGo
- func (sg *SGo) Any(path string, handler HandlerFunc)
- func (sg *SGo) CONNECT(path string, handler HandlerFunc)
- func (sg *SGo) DELETE(path string, handler HandlerFunc)
- func (sg *SGo) GET(path string, handler HandlerFunc)
- func (sg *SGo) HEAD(path string, handler HandlerFunc)
- func (sg *SGo) Handle(method, path string, handler HandlerFunc)
- func (sg *SGo) OPTIONS(path string, handler HandlerFunc)
- func (sg *SGo) PATCH(path string, handler HandlerFunc)
- func (sg *SGo) POST(path string, handler HandlerFunc)
- func (sg *SGo) PUT(path string, handler HandlerFunc)
- func (sg *SGo) Run(addr string) error
- func (sg *SGo) RunOverTLS(addr, certFile, keyFile string) error
- func (sg *SGo) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (sg *SGo) SetTemplates(tplDir string, funcMap template.FuncMap)
- func (sg *SGo) TRACE(path string, handler HandlerFunc)
- func (sg *SGo) USE(middlewares ...HandlerFunc)
- type Templates
- type Trie
Constants ¶
const ( CONNECT = http.MethodConnect DELETE = http.MethodDelete GET = http.MethodGet HEAD = http.MethodHead OPTIONS = http.MethodOptions PATCH = http.MethodPatch POST = http.MethodPost PUT = http.MethodPut TRACE = http.MethodTrace )
HTTP methods
Variables ¶
var PreflightHandler = func(ctx *Context) error { return ctx.Text(200, "") }
PreflightHandler is a dummy handler that handles preflight request when CORS
Functions ¶
func MethodNotAllowedHandler ¶
MethodNotAllowedHandler .
Types ¶
type Context ¶
type Context struct { Req *http.Request Resp *responseWriter // contains filtered or unexported fields }
Context provide a HTTP context for SGo.
func NewContext ¶
NewContext .
func (*Context) Init ¶
func (ctx *Context) Init(w http.ResponseWriter, r *http.Request)
Init the context gotten from sync pool.
type SGo ¶
type SGo struct { // Router is based on a radix/trie tree. Tree *Trie // Pool is for context. Pool *sync.Pool NotFoundHandler HandlerFunc MethodNotAllowedHandler HandlerFunc // Built-in templates render. Templates *Templates Middlewares []HandlerFunc }
SGo is Suuuuuuuuper Sweetie!
func (*SGo) Any ¶
func (sg *SGo) Any(path string, handler HandlerFunc)
Any register any method handler
func (*SGo) CONNECT ¶
func (sg *SGo) CONNECT(path string, handler HandlerFunc)
CONNECT register CONNECT request handler
func (*SGo) DELETE ¶
func (sg *SGo) DELETE(path string, handler HandlerFunc)
DELETE register DELETE request handler
func (*SGo) GET ¶
func (sg *SGo) GET(path string, handler HandlerFunc)
GET register GET request handler
func (*SGo) HEAD ¶
func (sg *SGo) HEAD(path string, handler HandlerFunc)
HEAD register HEAD request handler
func (*SGo) Handle ¶
func (sg *SGo) Handle(method, path string, handler HandlerFunc)
Handle register custom METHOD request HandlerFunc
func (*SGo) OPTIONS ¶
func (sg *SGo) OPTIONS(path string, handler HandlerFunc)
OPTIONS register OPTIONS request handler
func (*SGo) PATCH ¶
func (sg *SGo) PATCH(path string, handler HandlerFunc)
PATCH register PATCH request HandlerFunc
func (*SGo) POST ¶
func (sg *SGo) POST(path string, handler HandlerFunc)
POST register POST request handler
func (*SGo) PUT ¶
func (sg *SGo) PUT(path string, handler HandlerFunc)
PUT register PUT request handler
func (*SGo) RunOverTLS ¶
RunOverTLS .
func (*SGo) SetTemplates ¶
SetTemplates set the templates dir and funcMap.
func (*SGo) TRACE ¶
func (sg *SGo) TRACE(path string, handler HandlerFunc)
TRACE register TRACE request handler
type Templates ¶
type Templates struct { Dir string Suffix string FuncMap template.FuncMap // contains filtered or unexported fields }
Templates is a templates manager.
func NewTemplates ¶
NewTemplates .