Documentation
¶
Index ¶
- Constants
- func ListenAndServe(addr string, handler fasthttp.RequestHandler) error
- func ListenAndServeTLS(addr, certFile, keyFile string, handler fasthttp.RequestHandler) error
- func ListenAndServeTLSEmbed(addr string, certData, keyData []byte, handler fasthttp.RequestHandler) error
- func ListenAndServeUNIX(addr string, mode os.FileMode, handler fasthttp.RequestHandler) error
- type Application
- func (a *Application) AddRouter(domain string, r *Router)
- func (a *Application) Handler(ctx *fasthttp.RequestCtx)
- func (a *Application) NewRouter(domain string) *Router
- func (a *Application) Run()
- func (a *Application) SetDefaultRouter(r *Router)
- func (a *Application) SetLogger(logger fasthttp.Logger)
- func (a *Application) SetSessionStore(store sessions.Store)
- type Config
- type Context
- func (ctx *Context) Close()
- func (ctx *Context) HTML(body string)
- func (ctx *Context) HTMLWithCode(code int, body string)
- func (ctx *Context) JSON(v interface{})
- func (ctx *Context) JSONP(v interface{}, callback []byte)
- func (ctx *Context) JSONPWithCode(code int, v interface{}, callback []byte)
- func (ctx *Context) JSONWithCode(code int, v interface{})
- func (ctx *Context) Logger() fasthttp.Logger
- func (ctx *Context) SessionStore() sessions.Store
- func (ctx *Context) SetContentTypeToHTML()
- func (ctx *Context) SetContentTypeToJSON()
- func (ctx *Context) SetContentTypeToJSONP()
- func (ctx *Context) SetContentTypeToXML()
- func (ctx *Context) Text(a ...interface{})
- func (ctx *Context) Textf(format string, a ...interface{})
- func (ctx *Context) XML(v interface{}, headers ...string)
- func (ctx *Context) XMLWithCode(code int, v interface{}, headers ...string)
- type Controller
- func (c Controller) DELETE(ctx *Context)
- func (c Controller) GET(ctx *Context)
- func (c Controller) HEAD(ctx *Context)
- func (c Controller) Handle(next Handler) Handler
- func (c Controller) OPTIONS(ctx *Context)
- func (c Controller) PATCH(ctx *Context)
- func (c Controller) POST(ctx *Context)
- func (c Controller) PUT(ctx *Context)
- type ControllerInterface
- type Handler
- type HandlerFunc
- type Middleware
- type Router
- func (r *Router) AddMiddleware(middleware Middleware)
- func (r *Router) DELETE(path string, handler Handler)
- func (r *Router) GET(path string, handler Handler)
- func (r *Router) HEAD(path string, handler Handler)
- func (r *Router) Handle(method, path string, handler Handler)
- func (r *Router) OPTIONS(path string, handler Handler)
- func (r *Router) PATCH(path string, handler Handler)
- func (r *Router) POST(path string, handler Handler)
- func (r *Router) PUT(path string, handler Handler)
- func (r *Router) RegisterController(route string, c ControllerInterface)
- func (r *Router) SetLogger(logger fasthttp.Logger)
- func (r *Router) SetMiddlewares(middlewares []Middleware)
- func (r *Router) SetSessionStore(store sessions.Store)
Constants ¶
const ( // Version of CleverGo. Version = "1.1.1" // Logo of CleverGo. Logo = `` /* 256-byte string literal not displayed */ )
const ( // ServerTypeDefault means HTTP Application. ServerTypeDefault = 1 // ServerTypeUNIX means UNIX Application. ServerTypeUNIX = 2 // ServerTypeTLS means TLS Application. ServerTypeTLS = 3 // ServerTypeTLSEmbed means TLSEmbed Application. ServerTypeTLSEmbed = 4 )
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, handler fasthttp.RequestHandler) error
ListenAndServe is a alias of fasthttp.ListenAndServe.
func ListenAndServeTLS ¶
func ListenAndServeTLS(addr, certFile, keyFile string, handler fasthttp.RequestHandler) error
ListenAndServeTLS is a alias of fasthttp.ListenAndServeTLS.
func ListenAndServeTLSEmbed ¶
func ListenAndServeTLSEmbed(addr string, certData, keyData []byte, handler fasthttp.RequestHandler) error
ListenAndServeTLSEmbed is a alias of fasthttp.ListenAndServeTLSEmbed.
func ListenAndServeUNIX ¶
ListenAndServeUNIX is a alias of fasthttp.ListenAndServeUNIX.
Types ¶
type Application ¶ added in v1.0.2
type Application struct { Config *Config // configuration. // contains filtered or unexported fields }
Application for managing routers.
func NewApplication ¶ added in v1.0.2
func NewApplication() *Application
NewApplication returns an application's instance.
func (*Application) AddRouter ¶ added in v1.0.2
func (a *Application) AddRouter(domain string, r *Router)
AddRouter for adding router to application.
Set the current router as default router if the domain is an empty string.
func (*Application) Handler ¶ added in v1.0.2
func (a *Application) Handler(ctx *fasthttp.RequestCtx)
Handler returns application' Handler.
func (*Application) NewRouter ¶ added in v1.1.1
func (a *Application) NewRouter(domain string) *Router
NewRouter returns a new Router's instance.
Set the current router as default router if the domain is an empty string.
func (*Application) Run ¶ added in v1.0.2
func (a *Application) Run()
Run fro starting the application.
func (*Application) SetDefaultRouter ¶ added in v1.0.2
func (a *Application) SetDefaultRouter(r *Router)
SetDefaultRouter for setting default router.
func (*Application) SetLogger ¶ added in v1.0.2
func (a *Application) SetLogger(logger fasthttp.Logger)
SetLogger for setting logger.
func (*Application) SetSessionStore ¶ added in v1.0.2
func (a *Application) SetSessionStore(store sessions.Store)
SetSessionStore for setting session store.
type Config ¶ added in v1.0.2
type Config struct { ServerAddr string // Server address. ServerType int // Server type. ServerMode os.FileMode // Server mode for UNIX application. ServerCertFile string // CertFile for TLS application. ServerKeyFile string // KeyFile for TLS application. ServerCertData []byte // CertData for TLSEmbed application. ServerKeyData []byte // KeyData for TLSEmbed application. }
Config for Application.
func (*Config) IsServeTLS ¶ added in v1.0.2
IsServeTLS returns a boolean indicating whether is TLS Application.
func (*Config) IsServeTLSEmbed ¶ added in v1.0.2
IsServeTLSEmbed returns a boolean indicating whether is TLSEmbed Application.
func (*Config) IsServeUNIX ¶ added in v1.0.2
IsServeUNIX returns a boolean indicating whether is UNIX Application.
type Context ¶
type Context struct { *fasthttp.RequestCtx RouterParams *router.Params Session *sessions.Session // contains filtered or unexported fields }
Context of request.
It contains the router, session and params.
func NewContext ¶
NewContext returns a Context instance.
Firstly, it will try to get Context instance from contextPool. If failed to get Context from contextPool, returns a new Context instance.
func (*Context) Close ¶ added in v1.0.1
func (ctx *Context) Close()
Close Context.
Context should be closed after finishing request, and at this moment, put the context into contextPool.
func (*Context) HTMLWithCode ¶
HTMLWithCode responses HTML data and custom status code to client.
func (*Context) JSONPWithCode ¶
JSONPWithCode responses JSONP data and custom status code to client.
func (*Context) JSONWithCode ¶
JSONWithCode responses JSON data and custom status code to client.
func (*Context) Logger ¶ added in v1.0.2
Logger returns logger.
Returns the router's logger if the logger is non-nil. Otherwise, returns the default logger of ctx.
func (*Context) SessionStore ¶ added in v1.1.0
SessionStore returns the session store of router.
func (*Context) SetContentTypeToHTML ¶ added in v1.0.3
func (ctx *Context) SetContentTypeToHTML()
SetContentTypeToHTML set Content-Type to HTML.
func (*Context) SetContentTypeToJSON ¶ added in v1.0.3
func (ctx *Context) SetContentTypeToJSON()
SetContentTypeToJSON set Content-Type to JSON.
func (*Context) SetContentTypeToJSONP ¶ added in v1.0.3
func (ctx *Context) SetContentTypeToJSONP()
SetContentTypeToJSONP set Content-Type to JSONP.
func (*Context) SetContentTypeToXML ¶ added in v1.0.3
func (ctx *Context) SetContentTypeToXML()
SetContentTypeToXML set Content-Type to XML.
func (*Context) Text ¶
func (ctx *Context) Text(a ...interface{})
Text responses text data to client using fmt.Fprint().
func (*Context) XMLWithCode ¶
XMLWithCode responses XML data and custom status code to client.
type Controller ¶
type Controller struct{}
Controller is an empty struct.
func (Controller) DELETE ¶
func (c Controller) DELETE(ctx *Context)
DELETE for handling the DELETE request.
func (Controller) Handle ¶
func (c Controller) Handle(next Handler) Handler
Handle implemented Middleware Interface.
func (Controller) OPTIONS ¶
func (c Controller) OPTIONS(ctx *Context)
OPTIONS for handling the OPTIONS request.
func (Controller) PATCH ¶
func (c Controller) PATCH(ctx *Context)
PATCH for handling the PATCH request.
type ControllerInterface ¶
type ControllerInterface interface { Handle(next Handler) Handler // Implemented Middleware Interface. DELETE(ctx *Context) // Request handler for DELETE request. GET(ctx *Context) // Request handler for GET request. HEAD(ctx *Context) // Request handler for HEAD request. OPTIONS(ctx *Context) // Request handler for OPTIONS request. PATCH(ctx *Context) // Request handler for PATCH request. POST(ctx *Context) // Request handler for POST request. PUT(ctx *Context) // Request handler for PUT request. }
ControllerInterface contains the methods which the Controller should implements.
In fact, the controller is a middleware.
type HandlerFunc ¶
type HandlerFunc func(*Context)
The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers.
type Middleware ¶
Middleware Interface.
type Router ¶
Router for managing request handlers.
func (*Router) AddMiddleware ¶
func (r *Router) AddMiddleware(middleware Middleware)
AddMiddleware for adding middleware.
func (*Router) RegisterController ¶
func (r *Router) RegisterController(route string, c ControllerInterface)
RegisterController for registering controller.
The Controller should implemented the ControllerInterface.
func (*Router) SetMiddlewares ¶
func (r *Router) SetMiddlewares(middlewares []Middleware)
SetMiddlewares for setting middlewares.
func (*Router) SetSessionStore ¶
SetSessionStore for setting session store.