Documentation ¶
Overview ¶
Package iris the fastest go web framework in (this) Earth. /NOTE: When you see 'framework' or 'station' we mean the Iris web framework's main implementation.
Basic usage ----------------------------------------------------------------------
package main
import "github.com/kataras/iris"
func main() { iris.Get("/hi_json", func(c *iris.Context) { c.JSON(200, iris.Map{ "Name": "Iris", "Age": 2, }) }) iris.Listen(":8080") }
----------------------------------------------------------------------
package main
import "github.com/kataras/iris"
func main() { s1 := iris.New() s1.Get("/hi_json", func(c *iris.Context) { c.JSON(200, iris.Map{ "Name": "Iris", "Age": 2, }) }) s2 := iris.New() s2.Get("/hi_raw_html", func(c *iris.Context) { c.HTML(iris.StatusOK, "<b> Iris </b> welcomes <h1>you!</h1>") }) go s1.Listen(":8080") s2.Listen(":1993") }
-----------------------------DOCUMENTATION---------------------------- ----------------------------_______________--------------------------- For middleware, templates, sessions, websockets, mails, subdomains, dynamic subdomains, routes, party of subdomains & routes and much more visit https://www.gitbook.com/book/kataras/iris/details
Index ¶
- Constants
- Variables
- func API(path string, restAPI HandlerAPI, middleware ...HandlerFunc)
- func Any(registedPath string, handlersFn ...HandlerFunc)
- func Close()
- func CloseWithErr() error
- func EmitError(statusCode int, ctx *Context)
- func Listen(addr string)
- func ListenTLS(addr string, certFile string, keyFile string)
- func ListenTLSWithErr(addr string, certFile string, keyFile string) error
- func ListenUNIX(addr string, mode os.FileMode)
- func ListenUNIXWithErr(addr string, mode os.FileMode) error
- func ListenWithErr(addr string) error
- func Must(err error)
- func MustUse(handlers ...Handler)
- func MustUseFunc(handlersFn ...HandlerFunc)
- func OnError(statusCode int, handlerFn HandlerFunc)
- func Path(routeName string, args ...interface{}) string
- func StatusText(code int) string
- func TemplateString(templateFile string, pageContext interface{}, layout ...string) string
- func URL(routeName string, args ...interface{}) (url string)
- func URLEncode(path string) string
- func Use(handlers ...Handler)
- func UseFunc(handlersFn ...HandlerFunc)
- type Context
- func (ctx *Context) Clone() context.IContext
- func (ctx *Context) Data(status int, v []byte) error
- func (ctx *Context) Do()
- func (ctx *Context) EmitError(statusCode int)
- func (ctx *Context) ExecuteTemplate(tmpl *template.Template, pageContext interface{}) error
- func (ctx *Context) Get(key string) interface{}
- func (ctx *Context) GetCookie(name string) (val string)
- func (ctx *Context) GetFlash(key string) string
- func (ctx *Context) GetFlashBytes(key string) (value []byte, err error)
- func (ctx *Context) GetFmt(key string) func(format string, args ...interface{}) string
- func (ctx *Context) GetHandlerName() string
- func (ctx *Context) GetInt(key string) int
- func (ctx *Context) GetRequestCtx() *fasthttp.RequestCtx
- func (ctx *Context) GetString(key string) string
- func (ctx *Context) HTML(httpStatus int, htmlContents string)
- func (ctx *Context) HostString() string
- func (ctx *Context) IsStopped() bool
- func (ctx *Context) JSON(status int, v interface{}) error
- func (ctx *Context) JSONP(status int, callback string, v interface{}) error
- func (ctx *Context) Log(format string, a ...interface{})
- func (ctx *Context) Markdown(status int, markdown string)
- func (ctx *Context) MarkdownString(markdownText string) string
- func (ctx *Context) MethodString() string
- func (ctx *Context) MustRender(name string, binding interface{}, layout ...string)
- func (ctx *Context) Next()
- func (ctx *Context) NotFound()
- func (ctx *Context) Panic()
- func (ctx *Context) Param(key string) string
- func (ctx *Context) ParamInt(key string) (int, error)
- func (ctx *Context) PathString() string
- func (ctx *Context) PostFormMulti(name string) []string
- func (ctx *Context) PostFormValue(name string) string
- func (ctx *Context) ReadForm(formObject interface{}) error
- func (ctx *Context) ReadJSON(jsonObject interface{}) error
- func (ctx *Context) ReadXML(xmlObject interface{}) error
- func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int)
- func (ctx *Context) RedirectTo(routeName string, args ...interface{})
- func (ctx *Context) RemoteAddr() string
- func (ctx *Context) RemoveCookie(name string)
- func (ctx *Context) Render(name string, binding interface{}, layout ...string) error
- func (ctx *Context) RenderWithStatus(status int, name string, binding interface{}, layout ...string) error
- func (ctx *Context) RequestHeader(k string) string
- func (ctx *Context) RequestIP() string
- func (ctx *Context) RequestPath(escape bool) string
- func (ctx *Context) Reset(reqCtx *fasthttp.RequestCtx)
- func (ctx *Context) SendFile(filename string, destinationName string) error
- func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, ...) error
- func (ctx *Context) ServeFile(filename string, gzipCompression bool) error
- func (ctx *Context) Session() store.IStore
- func (ctx *Context) SessionDestroy()
- func (ctx *Context) Set(key string, value interface{})
- func (ctx *Context) SetContentType(s string)
- func (ctx *Context) SetCookie(cookie *fasthttp.Cookie)
- func (ctx *Context) SetCookieKV(key, value string)
- func (ctx *Context) SetFlash(key string, value string)
- func (ctx *Context) SetFlashBytes(key string, value []byte)
- func (ctx *Context) SetHeader(k string, v string)
- func (ctx *Context) StopExecution()
- func (ctx *Context) Stream(cb func(writer *bufio.Writer))
- func (ctx *Context) StreamReader(bodyStream io.Reader, bodySize int)
- func (ctx *Context) StreamWriter(cb func(writer *bufio.Writer))
- func (ctx *Context) Subdomain() (subdomain string)
- func (ctx *Context) TemplateString(name string, binding interface{}, layout ...string) string
- func (ctx *Context) Text(status int, v string) error
- func (ctx *Context) URLParam(key string) string
- func (ctx *Context) URLParamInt(key string) (int, error)
- func (ctx *Context) URLParams() map[string]string
- func (ctx *Context) VirtualHostname() string
- func (ctx *Context) Write(format string, a ...interface{})
- func (ctx *Context) XML(status int, v interface{}) error
- type Framework
- func (api Framework) API(path string, restAPI HandlerAPI, middleware ...HandlerFunc)
- func (api Framework) Any(registedPath string, handlersFn ...HandlerFunc)
- func (s *Framework) Close()
- func (s *Framework) CloseWithErr() error
- func (api Framework) Connect(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) Delete(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (s *Framework) EmitError(statusCode int, ctx *Context)
- func (api Framework) Favicon(favPath string, requestPath ...string) RouteNameFunc
- func (api Framework) Get(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) H_(method string, registedPath string, fn func(context.IContext)) func(string)
- func (api Framework) Handle(method string, registedPath string, handlers ...Handler) RouteNameFunc
- func (api Framework) HandleFunc(method string, registedPath string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) Head(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) Layout(tmplLayoutFile string) MuxAPI
- func (s *Framework) Listen(addr string)
- func (s *Framework) ListenTLS(addr string, certFile, keyFile string)
- func (s *Framework) ListenTLSWithErr(addr string, certFile string, keyFile string) error
- func (s *Framework) ListenUNIX(addr string, mode os.FileMode)
- func (s *Framework) ListenUNIXWithErr(addr string, mode os.FileMode) error
- func (s *Framework) ListenWithErr(addr string) error
- func (s *Framework) Lookup(routeName string) Route
- func (s *Framework) Lookups() (routes []Route)
- func (s *Framework) Must(err error)
- func (s *Framework) MustUse(handlers ...Handler)
- func (s *Framework) MustUseFunc(handlersFn ...HandlerFunc)
- func (s *Framework) NoListen() *Server
- func (s *Framework) OnError(statusCode int, handlerFn HandlerFunc)
- func (api Framework) Options(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) Party(relativePath string, handlersFn ...HandlerFunc) MuxAPI
- func (api Framework) Patch(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (s *Framework) Path(routeName string, args ...interface{}) string
- func (api Framework) Post(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) Put(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (api Framework) Static(relative string, systemPath string, stripSlashes int) RouteNameFunc
- func (api Framework) StaticContent(reqPath string, cType string, content []byte) func(string)
- func (api Framework) StaticFS(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
- func (api Framework) StaticHandler(systemPath string, stripSlashes int, compress bool, generateIndexPages bool, ...) HandlerFunc
- func (api Framework) StaticServe(systemPath string, requestPath ...string) RouteNameFunc
- func (api Framework) StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
- func (s *Framework) TemplateString(templateFile string, pageContext interface{}, layout ...string) string
- func (api Framework) Trace(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func (s *Framework) URL(routeName string, args ...interface{}) (url string)
- func (api Framework) Use(handlers ...Handler)
- func (api Framework) UseFunc(handlersFn ...HandlerFunc)
- type FrameworkAPI
- type Handler
- type HandlerAPI
- type HandlerFunc
- type Map
- type Middleware
- type MuxAPI
- type PathParameter
- type PathParameters
- type Plugin
- type PluginContainer
- type PluginDownloadManager
- type PostListenFunc
- type PreCloseFunc
- type PreDownloadFunc
- type PreListenFunc
- type Route
- type RouteNameFunc
- func Connect(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Delete(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Favicon(favPath string, requestPath ...string) RouteNameFunc
- func Get(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Handle(method string, registedPath string, handlers ...Handler) RouteNameFunc
- func HandleFunc(method string, registedPath string, handlersFn ...HandlerFunc) RouteNameFunc
- func Head(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Options(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Patch(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Post(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Put(path string, handlersFn ...HandlerFunc) RouteNameFunc
- func Static(relative string, systemPath string, stripSlashes int) RouteNameFunc
- func StaticContent(reqPath string, contentType string, content []byte) RouteNameFunc
- func StaticFS(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
- func StaticServe(systemPath string, requestPath ...string) RouteNameFunc
- func StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
- func Trace(path string, handlersFn ...HandlerFunc) RouteNameFunc
- type Server
- func (s *Server) FullHost() string
- func (s *Server) Host() (host string)
- func (s *Server) Hostname() (hostname string)
- func (s *Server) IsListening() bool
- func (s *Server) IsSecure() bool
- func (s *Server) Listener() net.Listener
- func (s *Server) Open() error
- func (s *Server) SetHandler(mux *serveMux)
- func (s *Server) VirtualHost() (host string)
- func (s *Server) VirtualHostname() (hostname string)
Constants ¶
const ( // MethodGet "GET" MethodGet = "GET" // MethodPost "POST" MethodPost = "POST" // MethodPut "PUT" MethodPut = "PUT" // MethodDelete "DELETE" MethodDelete = "DELETE" // MethodConnect "CONNECT" MethodConnect = "CONNECT" // MethodHead "HEAD" MethodHead = "HEAD" // MethodPatch "PATCH" MethodPatch = "PATCH" // MethodOptions "OPTIONS" MethodOptions = "OPTIONS" // MethodTrace "TRACE" MethodTrace = "TRACE" )
const ( // StatusContinue http status '100' StatusContinue = 100 // StatusSwitchingProtocols http status '101' StatusSwitchingProtocols = 101 // StatusOK http status '200' StatusOK = 200 // StatusCreated http status '201' StatusCreated = 201 // StatusAccepted http status '202' StatusAccepted = 202 // StatusNonAuthoritativeInfo http status '203' StatusNonAuthoritativeInfo = 203 // StatusNoContent http status '204' StatusNoContent = 204 // StatusResetContent http status '205' StatusResetContent = 205 // StatusPartialContent http status '206' StatusPartialContent = 206 // StatusMultipleChoices http status '300' StatusMultipleChoices = 300 // StatusMovedPermanently http status '301' StatusMovedPermanently = 301 // StatusFound http status '302' StatusFound = 302 // StatusSeeOther http status '303' StatusSeeOther = 303 // StatusNotModified http status '304' StatusNotModified = 304 // StatusUseProxy http status '305' StatusUseProxy = 305 // StatusTemporaryRedirect http status '307' StatusTemporaryRedirect = 307 // StatusBadRequest http status '400' StatusBadRequest = 400 StatusUnauthorized = 401 // StatusPaymentRequired http status '402' StatusPaymentRequired = 402 // StatusForbidden http status '403' StatusForbidden = 403 // StatusNotFound http status '404' StatusNotFound = 404 // StatusMethodNotAllowed http status '405' StatusMethodNotAllowed = 405 // StatusNotAcceptable http status '406' StatusNotAcceptable = 406 // StatusProxyAuthRequired http status '407' StatusProxyAuthRequired = 407 // StatusRequestTimeout http status '408' StatusRequestTimeout = 408 // StatusConflict http status '409' StatusConflict = 409 // StatusGone http status '410' StatusGone = 410 // StatusLengthRequired http status '411' StatusLengthRequired = 411 // StatusPreconditionFailed http status '412' StatusPreconditionFailed = 412 // StatusRequestEntityTooLarge http status '413' StatusRequestEntityTooLarge = 413 // StatusRequestURITooLong http status '414' StatusRequestURITooLong = 414 // StatusUnsupportedMediaType http status '415' StatusUnsupportedMediaType = 415 // StatusRequestedRangeNotSatisfiable http status '416' StatusRequestedRangeNotSatisfiable = 416 // StatusExpectationFailed http status '417' StatusExpectationFailed = 417 // StatusTeapot http status '418' StatusTeapot = 418 // StatusPreconditionRequired http status '428' StatusPreconditionRequired = 428 // StatusTooManyRequests http status '429' StatusTooManyRequests = 429 // StatusRequestHeaderFieldsTooLarge http status '431' StatusRequestHeaderFieldsTooLarge = 431 StatusUnavailableForLegalReasons = 451 // StatusInternalServerError http status '500' StatusInternalServerError = 500 // StatusNotImplemented http status '501' StatusNotImplemented = 501 // StatusBadGateway http status '502' StatusBadGateway = 502 StatusServiceUnavailable = 503 // StatusGatewayTimeout http status '504' StatusGatewayTimeout = 504 // StatusHTTPVersionNotSupported http status '505' StatusHTTPVersionNotSupported = 505 // StatusNetworkAuthenticationRequired http status '511' StatusNetworkAuthenticationRequired = 511 )
const ( // HTMLEngine conversion for config.HTMLEngine HTMLEngine = config.HTMLEngine // PongoEngine conversion for config.PongoEngine PongoEngine = config.PongoEngine // MarkdownEngine conversion for config.MarkdownEngine MarkdownEngine = config.MarkdownEngine // JadeEngine conversion for config.JadeEngine JadeEngine = config.JadeEngine // AmberEngine conversion for config.AmberEngine AmberEngine = config.AmberEngine // DefaultEngine conversion for config.DefaultEngine DefaultEngine = config.DefaultEngine // NoEngine conversion for config.NoEngine NoEngine = config.NoEngine // NoLayout to disable layout for a particular template file // conversion for config.NoLayout NoLayout = config.NoLayout )
const (
// Version of the iris
Version = "3.0.0-rc.3"
)
Variables ¶
var ( Default *Framework Config *config.Iris Logger *logger.Logger Plugins PluginContainer Websocket websocket.Server HTTPServer *Server )
Default entry, use it with iris.$anyPublicFunc
var ( // AllMethods "GET", "POST", "PUT", "DELETE", "CONNECT", "HEAD", "PATCH", "OPTIONS", "TRACE" AllMethods = [...]string{MethodGet, MethodPost, MethodPut, MethodDelete, MethodConnect, MethodHead, MethodPatch, MethodOptions, MethodTrace} )
var SkipBannerFlag bool
SkipBannerFlag, if enabled then means that this instance ran propably by an external software, which can disable the banner output by the command line argument '-s'
Functions ¶
func API ¶
func API(path string, restAPI HandlerAPI, middleware ...HandlerFunc)
API converts & registers a custom struct to the router receives two parameters first is the request path (string) second is the custom struct (interface{}) which can be anything that has a *iris.Context as field. third is the common middlewares, it's optional
Note that API's routes have their default-name to the full registed path, no need to give a special name for it, because it's not supposed to be used inside your templates.
Recommend to use when you retrieve data from an external database, and the router-performance is not the (only) thing which slows the server's overall performance.
This is a slow method, if you care about router-performance use the Handle/HandleFunc/Get/Post/Put/Delete/Trace/Options... instead
func Any ¶
func Any(registedPath string, handlersFn ...HandlerFunc)
Any registers a route for ALL of the http methods (Get,Post,Put,Head,Patch,Options,Connect,Delete)
func CloseWithErr ¶
func CloseWithErr() error
CloseWithErr terminates the server and returns an error if any
func EmitError ¶
EmitError fires a custom http error handler to the client
if no custom error defined with this statuscode, then iris creates one, and once at runtime
func Listen ¶
func Listen(addr string)
Listen starts the standalone http server which listens to the addr parameter which as the form of host:port
It panics on error if you need a func to return an error use the ListenWithErr ex: iris.Listen(":8080")
func ListenTLS ¶
ListenTLS Starts a https server with certificates, if you use this method the requests of the form of 'http://' will fail only https:// connections are allowed which listens to the addr parameter which as the form of host:port
It panics on error if you need a func to return an error use the ListenTLSWithErr ex: iris.ListenTLS(":8080","yourfile.cert","yourfile.key")
func ListenTLSWithErr ¶
ListenTLSWithErr Starts a https server with certificates, if you use this method the requests of the form of 'http://' will fail only https:// connections are allowed which listens to the addr parameter which as the form of host:port
It returns an error you are responsible how to handle this if you need a func to panic on error use the ListenTLS ex: log.Fatal(iris.ListenTLSWithErr(":8080","yourfile.cert","yourfile.key"))
func ListenUNIX ¶
ListenUNIX starts the process of listening to the new requests using a 'socket file', this works only on unix panics on error
func ListenUNIXWithErr ¶
ListenUNIXWithErr starts the process of listening to the new requests using a 'socket file', this works only on unix returns an error if something bad happens when trying to listen to
func ListenWithErr ¶
ListenWithErr starts the standalone http server which listens to the addr parameter which as the form of host:port
It returns an error you are responsible how to handle this if you need a func to panic on error use the Listen ex: log.Fatal(iris.ListenWithErr(":8080"))
func MustUse ¶
func MustUse(handlers ...Handler)
MustUse registers Handler middleware to the beginning, prepends them instead of append
Use it when you want to add a global middleware to all parties, to all routes in all subdomains It can be called after other, (but before .Listen of course)
func MustUseFunc ¶
func MustUseFunc(handlersFn ...HandlerFunc)
MustUseFunc registers HandlerFunc middleware to the beginning, prepends them instead of append
Use it when you want to add a global middleware to all parties, to all routes in all subdomains It can be called after other, (but before .Listen of course)
func OnError ¶
func OnError(statusCode int, handlerFn HandlerFunc)
OnError registers a custom http error handler
func Path ¶
Path used to check arguments with the route's named parameters and return the correct url if parse failed returns empty string
func StatusText ¶
StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.
func TemplateString ¶
TemplateString executes a template and returns its result as string, useful when you want it for sending rich e-mails returns empty string on error
func URL ¶
URL returns the subdomain+ host + Path(...optional named parameters if route is dynamic) returns an empty string if parse is failed
func URLEncode ¶
URLEncode returns the path encoded as url useful when you want to pass something to a database and be valid to retrieve it via context.Param use it only for special cases, when the default behavior doesn't suits you.
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
Credits to Manish Singh @kryptodev for URLEncode
Types ¶
type Context ¶
type Context struct { *fasthttp.RequestCtx Params PathParameters // contains filtered or unexported fields }
Context is resetting every time a request is coming to the server it is not good practice to use this object in goroutines, for these cases use the .Clone()
func (*Context) Do ¶
func (ctx *Context) Do()
Do calls the first handler only, it's like Next with negative pos, used only on Router&MemoryRouter
func (*Context) EmitError ¶
EmitError executes the custom error by the http status code passed to the function
func (*Context) ExecuteTemplate ¶
ExecuteTemplate executes a simple html template, you can use that if you already have the cached templates the recommended way to render is to use iris.Templates("./templates/path/*.html") and ctx.RenderFile("filename.html",struct{}) accepts 2 parameters the first parameter is the template (*template.Template) the second parameter is the page context (interfac{}) returns an error if any errors occurs while executing this template
func (*Context) GetCookie ¶
GetCookie returns cookie's value by it's name returns empty string if nothing was found
func (*Context) GetFlash ¶
GetFlash get a flash message by it's key after this action the messages is removed returns string, if the cookie doesn't exists the string is empty
func (*Context) GetFlashBytes ¶
GetFlashBytes get a flash message by it's key after this action the messages is removed returns []byte along with an error if the cookie doesn't exists or decode fails
func (*Context) GetFmt ¶
GetFmt returns a value which has this format: func(format string, args ...interface{}) string if doesn't exists returns nil
func (*Context) GetHandlerName ¶
GetHandlerName as requested returns the stack-name of the function which the Middleware is setted from
func (*Context) GetInt ¶
GetInt same as Get but returns the value as int if nothing founds returns -1
func (*Context) GetRequestCtx ¶
func (ctx *Context) GetRequestCtx() *fasthttp.RequestCtx
GetRequestCtx returns the current fasthttp context
func (*Context) GetString ¶
GetString same as Get but returns the value as string if nothing founds returns empty string ""
func (*Context) HostString ¶
HostString returns the Host of the request( the url as string )
func (*Context) IsStopped ¶
IsStopped checks and returns true if the current position of the Context is 255, means that the StopExecution has called
func (*Context) Markdown ¶
Markdown parses and renders to the client a particular (dynamic) markdown string accepts two parameters first is the http status code second is the markdown string
func (*Context) MarkdownString ¶
MarkdownString parses the (dynamic) markdown string and returns the converted html string
func (*Context) MethodString ¶
MethodString returns the HTTP Method
func (*Context) MustRender ¶
MustRender same as .Render but returns 500 internal server http status (error) if rendering fail
func (*Context) Next ¶
func (ctx *Context) Next()
Next calls all the next handler from the middleware stack, it used inside a middleware
func (*Context) NotFound ¶
func (ctx *Context) NotFound()
NotFound emits an error 404 to the client, using the custom http errors if no custom errors provided then it sends the default error message
func (*Context) Panic ¶
func (ctx *Context) Panic()
Panic emits an error 500 to the client, using the custom http errors if no custom errors rpovided then it sends the default error message
func (*Context) Param ¶
Param returns the string representation of the key's path named parameter's value
func (*Context) ParamInt ¶
ParamInt returns the int representation of the key's path named parameter's value
func (*Context) PathString ¶
PathString returns the full escaped path as string for unescaped use: ctx.RequestCtx.RequestURI() or RequestPath(escape bool)
func (*Context) PostFormMulti ¶
PostFormMulti returns a slice of string from post request's data
func (*Context) PostFormValue ¶
PostFormValue returns a single value from post request's data
func (*Context) ReadForm ¶
ReadForm binds the formObject with the form data it supports any kind of struct
func (*Context) Redirect ¶
Redirect redirect sends a redirect response the client accepts 2 parameters string and an optional int first parameter is the url to redirect second parameter is the http status should send, default is 302 (StatusFound), you can set it to 301 (Permant redirect), if that's nessecery
func (*Context) RedirectTo ¶
RedirectTo does the same thing as Redirect but instead of receiving a uri or path it receives a route name
func (*Context) RemoteAddr ¶
RemoteAddr is like RequestIP but it checks for proxy servers also, tries to get the real client's request IP
func (*Context) RemoveCookie ¶
RemoveCookie deletes a cookie by it's name/key
func (*Context) RenderWithStatus ¶
func (ctx *Context) RenderWithStatus(status int, name string, binding interface{}, layout ...string) error
RenderWithStatus builds up the response from the specified template and bindings. Note: parameter layout has meaning only when using the iris.HTMLTemplate
func (*Context) RequestHeader ¶
RequestHeader returns the request header's value accepts one parameter, the key of the header (string) returns string
func (*Context) RequestPath ¶
RequestPath returns the requested path
func (*Context) Reset ¶
func (ctx *Context) Reset(reqCtx *fasthttp.RequestCtx)
Reset resets the Context with a given domain.Response and domain.Request the context is ready-to-use after that, just like a new Context I use it for zero rellocation memory
func (*Context) SendFile ¶
SendFile sends file for force-download to the client
You can define your own "Content-Type" header also, after this function call for example: ctx.Response.Header.Set("Content-Type","thecontent/type")
func (*Context) ServeContent ¶
func (ctx *Context) ServeContent(content io.ReadSeeker, filename string, modtime time.Time, gzipCompression bool) error
ServeContent serves content, headers are autoset receives three parameters, it's low-level function, instead you can use .ServeFile(string)
You can define your own "Content-Type" header also, after this function call
func (*Context) ServeFile ¶
ServeFile serves a view file, to send a file ( zip for example) to the client you should use the SendFile(serverfilename,clientfilename) receives two parameters filename/path (string) gzipCompression (bool)
You can define your own "Content-Type" header also, after this function call
func (*Context) SessionDestroy ¶
func (ctx *Context) SessionDestroy()
SessionDestroy destroys the whole session, calls the provider's destroy and remove the cookie
func (*Context) SetContentType ¶
SetContentType sets the response writer's header key 'Content-Type' to a given value(s)
func (*Context) SetCookieKV ¶
SetCookieKV adds a cookie, receives just a key(string) and a value(string)
func (*Context) SetFlash ¶
SetFlash sets a flash message, accepts 2 parameters the key(string) and the value(string)
func (*Context) SetFlashBytes ¶
SetFlashBytes sets a flash message, accepts 2 parameters the key(string) and the value([]byte)
func (*Context) SetHeader ¶
SetHeader write to the response writer's header to a given key the given value(s)
Note: If you want to send a multi-line string as header's value use: strings.TrimSpace first.
func (*Context) StopExecution ¶
func (ctx *Context) StopExecution()
StopExecution just sets the .pos to 255 in order to not move to the next middlewares(if any)
func (*Context) StreamReader ¶
StreamReader sets response body stream and, optionally body size.
If bodySize is >= 0, then the bodyStream must provide exactly bodySize bytes before returning io.EOF.
If bodySize < 0, then bodyStream is read until io.EOF.
bodyStream.Close() is called after finishing reading all body data if it implements io.Closer.
See also StreamReader.
func (*Context) StreamWriter ¶
StreamWriter registers the given stream writer for populating response body.
This function may be used in the following cases:
- if response body is too big (more than 10MB).
- if response body is streamed from slow external sources.
- if response body must be streamed to the client in chunks. (aka `http server push`).
func (*Context) TemplateString ¶
TemplateString accepts a template filename, its context data and returns the result of the parsed template (string) if any error returns empty string
func (*Context) URLParamInt ¶
URLParamInt returns the get parameter int value from a request , if any
func (*Context) VirtualHostname ¶
VirtualHostname returns the hostname that user registers, host path maybe differs from the real which is HostString, which taken from a net.listener
type Framework ¶
type Framework struct { // fields which are useful to the user/dev HTTPServer *Server Config *config.Iris Logger *logger.Logger Plugins PluginContainer Websocket websocket.Server // contains filtered or unexported fields }
Framework is our God |\| Google.Search('Greek mythology Iris')
Implements the FrameworkAPI
func New ¶
New creates and returns a new Iris station aka Framework.
Receives an optional config.Iris as parameter If empty then config.Default() is used instead
func (Framework) API ¶
func (api Framework) API(path string, restAPI HandlerAPI, middleware ...HandlerFunc)
API converts & registers a custom struct to the router receives two parameters first is the request path (string) second is the custom struct (interface{}) which can be anything that has a *iris.Context as field. third is the common middleware, it's optional
Note that API's routes have their default-name to the full registed path, no need to give a special name for it, because it's not supposed to be used inside your templates.
Recommend to use when you retrieve data from an external database, and the router-performance is not the (only) thing which slows the server's overall performance.
This is a slow method, if you care about router-performance use the Handle/HandleFunc/Get/Post/Put/Delete/Trace/Options... instead
func (Framework) Any ¶
func (api Framework) Any(registedPath string, handlersFn ...HandlerFunc)
Any registers a route for ALL of the http methods (Get,Post,Put,Head,Patch,Options,Connect,Delete)
func (*Framework) Close ¶
func (s *Framework) Close()
Close terminates the server and panic if error occurs
func (*Framework) CloseWithErr ¶
CloseWithErr terminates the server and returns an error if any
func (Framework) Connect ¶
func (api Framework) Connect(path string, handlersFn ...HandlerFunc) RouteNameFunc
Connect registers a route for the Connect http method
func (Framework) Delete ¶
func (api Framework) Delete(path string, handlersFn ...HandlerFunc) RouteNameFunc
Delete registers a route for the Delete http method
func (*Framework) EmitError ¶
EmitError fires a custom http error handler to the client
if no custom error defined with this statuscode, then iris creates one, and once at runtime
func (Framework) Favicon ¶
func (api Framework) Favicon(favPath string, requestPath ...string) RouteNameFunc
Favicon serves static favicon accepts 2 parameters, second is optional favPath (string), declare the system directory path of the __.ico requestPath (string), it's the route's path, by default this is the "/favicon.ico" because some browsers tries to get this by default first, you can declare your own path if you have more than one favicon (desktop, mobile and so on)
this func will add a route for you which will static serve the /yuorpath/yourfile.ico to the /yourfile.ico (nothing special that you can't handle by yourself) Note that you have to call it on every favicon you have to serve automatically (dekstop, mobile and so on)
panics on error
func (Framework) Get ¶
func (api Framework) Get(path string, handlersFn ...HandlerFunc) RouteNameFunc
Get registers a route for the Get http method
func (Framework) H_ ¶
H_ is used to convert a context.IContext handler func to iris.HandlerFunc, is used only inside iris internal package to avoid import cycles
func (Framework) Handle ¶
func (api Framework) Handle(method string, registedPath string, handlers ...Handler) RouteNameFunc
Handle registers a route to the server's router if empty method is passed then registers handler(s) for all methods, same as .Any, but returns nil as result
func (Framework) HandleFunc ¶
func (api Framework) HandleFunc(method string, registedPath string, handlersFn ...HandlerFunc) RouteNameFunc
HandleFunc registers and returns a route with a method string, path string and a handler registedPath is the relative url path
func (Framework) Head ¶
func (api Framework) Head(path string, handlersFn ...HandlerFunc) RouteNameFunc
Head registers a route for the Head http method
func (Framework) Layout ¶
Layout oerrides the parent template layout with a more specific layout for this Party returns this Party, to continue as normal example: my := iris.Party("/my").Layout("layouts/mylayout.html")
{ my.Get("/", func(ctx *iris.Context) { ctx.MustRender("page1.html", nil) }) }
func (*Framework) Listen ¶
Listen starts the standalone http server which listens to the addr parameter which as the form of host:port
It panics on error if you need a func to return an error use the ListenWithErr ex: iris.Listen(":8080")
func (*Framework) ListenTLS ¶
ListenTLS Starts a https server with certificates, if you use this method the requests of the form of 'http://' will fail only https:// connections are allowed which listens to the addr parameter which as the form of host:port
It panics on error if you need a func to return an error use the ListenTLSWithErr ex: iris.ListenTLS(":8080","yourfile.cert","yourfile.key")
func (*Framework) ListenTLSWithErr ¶
ListenTLSWithErr Starts a https server with certificates, if you use this method the requests of the form of 'http://' will fail only https:// connections are allowed which listens to the addr parameter which as the form of host:port
It returns an error you are responsible how to handle this if you need a func to panic on error use the ListenTLS ex: log.Fatal(iris.ListenTLSWithErr(":8080","yourfile.cert","yourfile.key"))
func (*Framework) ListenUNIX ¶
ListenUNIX starts the process of listening to the new requests using a 'socket file', this works only on unix panics on error
func (*Framework) ListenUNIXWithErr ¶
ListenUNIXWithErr starts the process of listening to the new requests using a 'socket file', this works only on unix returns an error if something bad happens when trying to listen to
func (*Framework) ListenWithErr ¶
ListenWithErr starts the standalone http server which listens to the addr parameter which as the form of host:port
It returns an error you are responsible how to handle this if you need a func to panic on error use the Listen ex: log.Fatal(iris.ListenWithErr(":8080"))
func (*Framework) MustUse ¶
MustUse registers Handler middleware to the beginning, prepends them instead of append
Use it when you want to add a global middleware to all parties, to all routes in all subdomains It can be called after other, (but before .Listen of course)
func (*Framework) MustUseFunc ¶
func (s *Framework) MustUseFunc(handlersFn ...HandlerFunc)
MustUseFunc registers HandlerFunc middleware to the beginning, prepends them instead of append
Use it when you want to add a global middleware to all parties, to all routes in all subdomains It can be called after other, (but before .Listen of course)
func (*Framework) NoListen ¶
NoListen is useful only when you want to test Iris, it doesn't starts the server but it configures and returns it initializes the whole framework but server doesn't listens to a specific net.Listener
func (*Framework) OnError ¶
func (s *Framework) OnError(statusCode int, handlerFn HandlerFunc)
OnError registers a custom http error handler
func (Framework) Options ¶
func (api Framework) Options(path string, handlersFn ...HandlerFunc) RouteNameFunc
Options registers a route for the Options http method
func (Framework) Party ¶
func (api Framework) Party(relativePath string, handlersFn ...HandlerFunc) MuxAPI
Party is just a group joiner of routes which have the same prefix and share same middleware(s) also. Party can also be named as 'Join' or 'Node' or 'Group' , Party chosen because it has more fun
func (Framework) Patch ¶
func (api Framework) Patch(path string, handlersFn ...HandlerFunc) RouteNameFunc
Patch registers a route for the Patch http method
func (*Framework) Path ¶
Path used to check arguments with the route's named parameters and return the correct url if parse failed returns empty string
func (Framework) Post ¶
func (api Framework) Post(path string, handlersFn ...HandlerFunc) RouteNameFunc
Post registers a route for the Post http method
func (Framework) Put ¶
func (api Framework) Put(path string, handlersFn ...HandlerFunc) RouteNameFunc
Put registers a route for the Put http method
func (Framework) Static ¶
func (api Framework) Static(relative string, systemPath string, stripSlashes int) RouteNameFunc
Static registers a route which serves a system directory this doesn't generates an index page which list all files no compression is used also, for these features look at StaticFS func accepts three parameters first parameter is the request url path (string) second parameter is the system directory (string) third parameter is the level (int) of stripSlashes * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: ""
func (Framework) StaticContent ¶
StaticContent serves bytes, memory cached, on the reqPath a good example of this is how the websocket server uses that to auto-register the /iris-ws.js
func (Framework) StaticFS ¶
func (api Framework) StaticFS(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
StaticFS registers a route which serves a system directory this is the fastest method to serve static files generates an index page which list all files if you use this method it will generate compressed files also think this function as small fileserver with http accepts three parameters first parameter is the request url path (string) second parameter is the system directory (string) third parameter is the level (int) of stripSlashes * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: ""
func (Framework) StaticHandler ¶
func (api Framework) StaticHandler(systemPath string, stripSlashes int, compress bool, generateIndexPages bool, indexNames []string) HandlerFunc
StaticHandler returns a Handler to serve static system directory Accepts 5 parameters
first is the systemPath (string) Path to the root directory to serve files from.
second is the stripSlashes (int) level * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: ""
third is the compress (bool) Transparently compresses responses if set to true.
The server tries minimizing CPU usage by caching compressed files. It adds fasthttp.FSCompressedFileSuffix suffix to the original file name and tries saving the resulting compressed file under the new file name. So it is advisable to give the server write access to Root and to all inner folders in order to minimze CPU usage when serving compressed responses.
fourth is the generateIndexPages (bool) Index pages for directories without files matching IndexNames are automatically generated if set.
Directory index generation may be quite slow for directories with many files (more than 1K), so it is discouraged enabling index pages' generation for such directories.
fifth is the indexNames ([]string) List of index file names to try opening during directory access.
For example:
- index.html
- index.htm
- my-super-index.xml
func (Framework) StaticServe ¶
func (api Framework) StaticServe(systemPath string, requestPath ...string) RouteNameFunc
StaticServe serves a directory as web resource it's the simpliest form of the Static* functions Almost same usage as StaticWeb accepts only one required parameter which is the systemPath ( the same path will be used to register the GET&HEAD routes) if second parameter is empty, otherwise the requestPath is the second parameter it uses gzip compression (compression on each request, no file cache)
func (Framework) StaticWeb ¶
func (api Framework) StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
StaticWeb same as Static but if index.html exists and request uri is '/' then display the index.html's contents accepts three parameters first parameter is the request url path (string) second parameter is the system directory (string) third parameter is the level (int) of stripSlashes * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: "" * if you don't know what to put on stripSlashes just 1
func (*Framework) TemplateString ¶
func (s *Framework) TemplateString(templateFile string, pageContext interface{}, layout ...string) string
TemplateString executes a template and returns its result as string, useful when you want it for sending rich e-mails returns empty string on error
func (Framework) Trace ¶
func (api Framework) Trace(path string, handlersFn ...HandlerFunc) RouteNameFunc
Trace registers a route for the Trace http method
func (*Framework) URL ¶
URL returns the subdomain+ host + Path(...optional named parameters if route is dynamic) returns an empty string if parse is failed
func (Framework) Use ¶
func (api Framework) Use(handlers ...Handler)
Use registers Handler middleware
func (Framework) UseFunc ¶
func (api Framework) UseFunc(handlersFn ...HandlerFunc)
UseFunc registers HandlerFunc middleware
type FrameworkAPI ¶
type FrameworkAPI interface { MuxAPI Must(error) ListenWithErr(string) error Listen(string) ListenTLSWithErr(string, string, string) error ListenTLS(string, string, string) ListenUNIXWithErr(string, os.FileMode) error ListenUNIX(string, os.FileMode) NoListen() *Server Close() // global middleware prepending, registers to all subdomains, to all parties, you can call it at the last also MustUse(...Handler) MustUseFunc(...HandlerFunc) OnError(int, HandlerFunc) EmitError(int, *Context) Lookup(string) Route Lookups() []Route Path(string, ...interface{}) string URL(string, ...interface{}) string TemplateString(string, interface{}, ...string) string }
FrameworkAPI contains the main Iris Public API
type Handler ¶
type Handler interface {
Serve(ctx *Context)
}
Handler the main Iris Handler interface.
func ToHandler ¶
func ToHandler(handler interface{}) Handler
ToHandler converts an httapi.Handler or http.HandlerFunc to an iris.Handler
func ToHandlerFastHTTP ¶
func ToHandlerFastHTTP(h fasthttp.RequestHandler) Handler
ToHandlerFastHTTP converts an fasthttp.RequestHandler to an iris.Handler
type HandlerFunc ¶
type HandlerFunc func(*Context)
HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func StaticHandler ¶
func StaticHandler(systemPath string, stripSlashes int, compress bool, generateIndexPages bool, indexNames []string) HandlerFunc
StaticHandler returns a Handler to serve static system directory Accepts 5 parameters
first is the systemPath (string) Path to the root directory to serve files from.
second is the stripSlashes (int) level * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: ""
third is the compress (bool) Transparently compresses responses if set to true.
The server tries minimizing CPU usage by caching compressed files. It adds fasthttp.FSCompressedFileSuffix suffix to the original file name and tries saving the resulting compressed file under the new file name. So it is advisable to give the server write access to Root and to all inner folders in order to minimze CPU usage when serving compressed responses.
fourth is the generateIndexPages (bool) Index pages for directories without files matching IndexNames are automatically generated if set.
Directory index generation may be quite slow for directories with many files (more than 1K), so it is discouraged enabling index pages' generation for such directories.
fifth is the indexNames ([]string) List of index file names to try opening during directory access.
For example:
- index.html
- index.htm
- my-super-index.xml
func ToHandlerFunc ¶
func ToHandlerFunc(handler interface{}) HandlerFunc
ToHandlerFunc converts an http.Handler or http.HandlerFunc to an iris.HandlerFunc
func (HandlerFunc) Serve ¶
func (h HandlerFunc) Serve(ctx *Context)
Serve implements the Handler, is like ServeHTTP but for Iris
type Middleware ¶
type Middleware []Handler
Middleware is just a slice of Handler []func(c *Context)
type MuxAPI ¶
type MuxAPI interface { Party(string, ...HandlerFunc) MuxAPI // middleware serial, appending Use(...Handler) UseFunc(...HandlerFunc) // main handlers Handle(string, string, ...Handler) RouteNameFunc HandleFunc(string, string, ...HandlerFunc) RouteNameFunc // H_ is used to convert a context.IContext handler func to iris.HandlerFunc, is used only inside iris internal package to avoid import cycles H_(string, string, func(context.IContext)) func(string) API(string, HandlerAPI, ...HandlerFunc) // http methods Get(string, ...HandlerFunc) RouteNameFunc Post(string, ...HandlerFunc) RouteNameFunc Put(string, ...HandlerFunc) RouteNameFunc Delete(string, ...HandlerFunc) RouteNameFunc Connect(string, ...HandlerFunc) RouteNameFunc Head(string, ...HandlerFunc) RouteNameFunc Options(string, ...HandlerFunc) RouteNameFunc Patch(string, ...HandlerFunc) RouteNameFunc Trace(string, ...HandlerFunc) RouteNameFunc Any(string, ...HandlerFunc) // static content StaticHandler(string, int, bool, bool, []string) HandlerFunc Static(string, string, int) RouteNameFunc StaticFS(string, string, int) RouteNameFunc StaticWeb(string, string, int) RouteNameFunc StaticServe(string, ...string) RouteNameFunc StaticContent(string, string, []byte) func(string) Favicon(string, ...string) RouteNameFunc // templates Layout(string) MuxAPI // returns itself }
MuxAPI the visible api for the serveMux
func Party ¶
func Party(relativePath string, handlersFn ...HandlerFunc) MuxAPI
Party is just a group joiner of routes which have the same prefix and share same middleware(s) also. Party can also be named as 'Join' or 'Node' or 'Group' , Party chosen because it has more fun
type PathParameter ¶
PathParameter is a struct which contains Key and Value, used for named path parameters
type PathParameters ¶
type PathParameters []PathParameter
PathParameters type for a slice of PathParameter Tt's a slice of PathParameter type, because it's faster than map
func ParseParams ¶
func ParseParams(str string) PathParameters
ParseParams receives a string and returns PathParameters (slice of PathParameter) received string must have this form: key1=value1,key2=value2...
func (PathParameters) Get ¶
func (params PathParameters) Get(key string) string
Get returns a value from a key inside this Parameters If no parameter with this key given then it returns an empty string
func (PathParameters) String ¶
func (params PathParameters) String() string
String returns a string implementation of all parameters that this PathParameters object keeps hasthe form of key1=value1,key2=value2...
type Plugin ¶
type Plugin interface { }
Plugin just an empty base for plugins A Plugin can be added with: .Add(PreListenFunc(func(*Framework))) and so on... or .Add(myPlugin{},myPlugin2{}) which myPlugin is a struct with any of the methods below or .PostListen(func(*Framework)) and so on...
type PluginContainer ¶
type PluginContainer interface { Add(...Plugin) error Remove(string) error GetName(Plugin) string GetDescription(Plugin) string GetByName(string) Plugin Printf(string, ...interface{}) PreListen(PreListenFunc) DoPreListen(*Framework) DoPreListenParallel(*Framework) PostListen(PostListenFunc) DoPostListen(*Framework) PreClose(PreCloseFunc) DoPreClose(*Framework) PreDownload(PreDownloadFunc) DoPreDownload(Plugin, string) // custom event callbacks On(string, ...func()) Call(string) // GetAll() []Plugin // GetDownloader is the only one module that is used and fire listeners at the same time in this file GetDownloader() PluginDownloadManager }
PluginContainer is the interface which the pluginContainer should implements
type PluginDownloadManager ¶
type PluginDownloadManager interface { DirectoryExists(string) bool DownloadZip(string, string) (string, error) Unzip(string, string) (string, error) Remove(string) error // install is just the flow of: downloadZip -> unzip -> removeFile(zippedFile) // accepts 2 parameters // // first parameter is the remote url file zip // second parameter is the target directory // returns a string(installedDirectory) and an error // // (string) installedDirectory is the directory which the zip file had, this is the real installation path, you don't need to know what it's because these things maybe change to the future let's keep it to return the correct path. // the installedDirectory is not empty when the installation is succed, the targetDirectory is not already exists and no error happens // the installedDirectory is empty when the installation is already done by previous time or an error happens Install(remoteFileZip string, targetDirectory string) (string, error) }
PluginDownloadManager is the interface which the DownloadManager should implements
type PostListenFunc ¶
type PostListenFunc func(*Framework)
PostListenFunc implements the simple function listener for the PostListen(*Framework)
func (PostListenFunc) PostListen ¶
func (fn PostListenFunc) PostListen(station *Framework)
PostListen it's being called only one time, AFTER the Server is started (if .Listen called) parameter is the station
type PreCloseFunc ¶
type PreCloseFunc func(*Framework)
PreCloseFunc implements the simple function listener for the PreClose(*Framework)
func (PreCloseFunc) PreClose ¶
func (fn PreCloseFunc) PreClose(station *Framework)
PreClose it's being called only one time, BEFORE the Iris .Close method any plugin cleanup/clear memory happens here
The plugin is deactivated after this state
type PreDownloadFunc ¶
PreDownloadFunc implements the simple function listener for the PreDownload(plugin,string)
func (PreDownloadFunc) PreDownload ¶
func (fn PreDownloadFunc) PreDownload(pl Plugin, downloadURL string)
PreDownload it's being called every time a plugin tries to download something
first parameter is the plugin second parameter is the download url must return a boolean, if false then the plugin is not permmited to download this file
type PreListenFunc ¶
type PreListenFunc func(*Framework)
PreListenFunc implements the simple function listener for the PreListen(*Framework)
func (PreListenFunc) PreListen ¶
func (fn PreListenFunc) PreListen(station *Framework)
PreListen it's being called only one time, BEFORE the Server is started (if .Listen called) is used to do work at the time all other things are ready to go
parameter is the station
type Route ¶
type Route interface { // Name returns the name of the route Name() string // Subdomain returns the subdomain,if any Subdomain() string // Method returns the http method Method() string // Path returns the path Path() string // Middleware returns the slice of Handler([]Handler) registed to this route Middleware() Middleware }
Route contains some useful information about a route
type RouteNameFunc ¶
type RouteNameFunc func(string)
RouteNameFunc the func returns from the MuxAPi's methods, optionally sets the name of the Route (*route)
func Connect ¶
func Connect(path string, handlersFn ...HandlerFunc) RouteNameFunc
Connect registers a route for the Connect http method
func Delete ¶
func Delete(path string, handlersFn ...HandlerFunc) RouteNameFunc
Delete registers a route for the Delete http method
func Favicon ¶
func Favicon(favPath string, requestPath ...string) RouteNameFunc
Favicon serves static favicon accepts 2 parameters, second is optional favPath (string), declare the system directory path of the __.ico requestPath (string), it's the route's path, by default this is the "/favicon.ico" because some browsers tries to get this by default first, you can declare your own path if you have more than one favicon (desktop, mobile and so on)
this func will add a route for you which will static serve the /yuorpath/yourfile.ico to the /yourfile.ico (nothing special that you can't handle by yourself) Note that you have to call it on every favicon you have to serve automatically (dekstop, mobile and so on)
panics on error
func Get ¶
func Get(path string, handlersFn ...HandlerFunc) RouteNameFunc
Get registers a route for the Get http method
func Handle ¶
func Handle(method string, registedPath string, handlers ...Handler) RouteNameFunc
Handle registers a route to the server's router if empty method is passed then registers handler(s) for all methods, same as .Any, but returns nil as result
func HandleFunc ¶
func HandleFunc(method string, registedPath string, handlersFn ...HandlerFunc) RouteNameFunc
HandleFunc registers and returns a route with a method string, path string and a handler registedPath is the relative url path
func Head ¶
func Head(path string, handlersFn ...HandlerFunc) RouteNameFunc
Head registers a route for the Head http method
func Options ¶
func Options(path string, handlersFn ...HandlerFunc) RouteNameFunc
Options registers a route for the Options http method
func Patch ¶
func Patch(path string, handlersFn ...HandlerFunc) RouteNameFunc
Patch registers a route for the Patch http method
func Post ¶
func Post(path string, handlersFn ...HandlerFunc) RouteNameFunc
Post registers a route for the Post http method
func Put ¶
func Put(path string, handlersFn ...HandlerFunc) RouteNameFunc
Put registers a route for the Put http method
func Static ¶
func Static(relative string, systemPath string, stripSlashes int) RouteNameFunc
Static registers a route which serves a system directory this doesn't generates an index page which list all files no compression is used also, for these features look at StaticFS func accepts three parameters first parameter is the request url path (string) second parameter is the system directory (string) third parameter is the level (int) of stripSlashes * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: ""
func StaticContent ¶
func StaticContent(reqPath string, contentType string, content []byte) RouteNameFunc
StaticContent serves bytes, memory cached, on the reqPath a good example of this is how the websocket server uses that to auto-register the /iris-ws.js
func StaticFS ¶
func StaticFS(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
StaticFS registers a route which serves a system directory this is the fastest method to serve static files generates an index page which list all files if you use this method it will generate compressed files also think this function as small fileserver with http accepts three parameters first parameter is the request url path (string) second parameter is the system directory (string) third parameter is the level (int) of stripSlashes * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: ""
func StaticServe ¶
func StaticServe(systemPath string, requestPath ...string) RouteNameFunc
StaticServe serves a directory as web resource it's the simpliest form of the Static* functions Almost same usage as StaticWeb accepts only one required parameter which is the systemPath ( the same path will be used to register the GET&HEAD routes) if second parameter is empty, otherwise the requestPath is the second parameter it uses gzip compression (compression on each request, no file cache)
func StaticWeb ¶
func StaticWeb(reqPath string, systemPath string, stripSlashes int) RouteNameFunc
StaticWeb same as Static but if index.html exists and request uri is '/' then display the index.html's contents accepts three parameters first parameter is the request url path (string) second parameter is the system directory (string) third parameter is the level (int) of stripSlashes * stripSlashes = 0, original path: "/foo/bar", result: "/foo/bar" * stripSlashes = 1, original path: "/foo/bar", result: "/bar" * stripSlashes = 2, original path: "/foo/bar", result: "" * if you don't know what to put on stripSlashes just 1
func Trace ¶
func Trace(path string, handlersFn ...HandlerFunc) RouteNameFunc
Trace registers a route for the Trace http method
type Server ¶
type Server struct { *fasthttp.Server Config *config.Server // contains filtered or unexported fields }
Server the http server
func NoListen ¶
func NoListen() *Server
NoListen is useful only when you want to test Iris, it doesn't starts the server but it configures and returns it
func (*Server) Host ¶
Host returns the Listener().Addr().String(), if server is not listening it returns the config.ListeningAddr
func (*Server) Hostname ¶
Hostname returns the hostname part only, if host == localhost:8080 it will return the localhost if server is not listening it returns the config.ListeningAddr's hostname part
func (*Server) IsListening ¶
IsListening returns true if server is listening/started, otherwise false
func (*Server) Open ¶
Open opens/starts/runs/listens (to) the server, listen tls if Cert && Key is registed, listenUNIX if Mode is registed, otherwise listen
func (*Server) SetHandler ¶
func (s *Server) SetHandler(mux *serveMux)
SetHandler sets the handler in order to listen on client requests
func (*Server) VirtualHost ¶
VirtualHost returns the s.Config.ListeningAddr
func (*Server) VirtualHostname ¶
VirtualHostname returns the hostname that user registers, host path maybe differs from the real which is HostString, which taken from a net.listener
Directories ¶
Path | Synopsis |
---|---|
Package config defines the default settings and semantic variables
|
Package config defines the default settings and semantic variables |
render
|
|
template/engine/jade
Package jade the JadeEngine's functionality lives inside ../html now
|
Package jade the JadeEngine's functionality lives inside ../html now |
store
Package store the package is in diffent folder to reduce the import cycles from the ./context/context.go *
|
Package store the package is in diffent folder to reduce the import cycles from the ./context/context.go * |