Documentation ¶
Index ¶
- Constants
- func Black(msg string) string
- func Blue(msg string) string
- func Cyan(msg string) string
- func GetBytes(s string) (bs []byte)
- func GetString(b []byte) string
- func Green(msg string) string
- func ImmutableString(s string) string
- func Magenta(msg string) string
- func Red(msg string) string
- func SetColor(msg string, conf, bg, text int) string
- func White(msg string) string
- func Yellow(msg string) string
- type Cookie
- type Core
- func (c *Core) Build() error
- func (c *Core) Get(args ...interface{}) *Core
- func (c *Core) LoadTpls(tpls map[string]string) error
- func (c *Core) RegView(viewEngine ViewEngine)
- func (c *Core) Serve(address interface{}, tlsopt ...*tls.Config) error
- func (c *Core) Static(prefix, root string, config ...Static) *Core
- func (c *Core) Use(args ...interface{}) *Core
- func (c *Core) View(writer io.Writer, filename string, layout string, bind interface{}) error
- type Ctx
- func (c *Ctx) Body() string
- func (c *Ctx) ClearCookie(key ...string)
- func (c *Ctx) Cookie(cookie *Cookie)
- func (c *Ctx) Cookies(key ...string) (value string)
- func (c *Ctx) Domain(bases []string) string
- func (c *Ctx) Download(file string, name ...string)
- func (c *Ctx) FormValue(k string) (v string)
- func (c *Ctx) Fresh() bool
- func (c *Ctx) Get(k string) string
- func (c Ctx) Host() string
- func (c *Ctx) Hostname() string
- func (c *Ctx) IP() string
- func (c *Ctx) IPs() []string
- func (c *Ctx) JSON(data interface{}) error
- func (c *Ctx) JSONP(data interface{}, callback ...string) error
- func (ctx *Ctx) Method(override ...string) string
- func (c *Ctx) Next(err ...error)
- func (c *Ctx) Params(k string) (v string)
- func (c *Ctx) Path() string
- func (c *Ctx) Query(k string) (value string)
- func (c *Ctx) ReadBody(out interface{}) error
- func (c *Ctx) Redirect(path string, status ...int)
- func (c *Ctx) Render(filename string, optionalViewModel ...interface{}) error
- func (c *Ctx) RootDomain(offset ...int) string
- func (c *Ctx) Router() *Route
- func (c *Ctx) SaveFile(fileheader *multipart.FileHeader, path string) error
- func (c *Ctx) Send(bodies ...interface{})
- func (c *Ctx) SendFile(file string, noCompression ...bool)
- func (c *Ctx) SendStatus(code int)
- func (c *Ctx) Set(k, v string)
- func (c *Ctx) Subdomains(offset ...int) string
- func (c *Ctx) ToJSON(data interface{}, err error) error
- func (c *Ctx) Vars(k string, v ...interface{}) (val interface{})
- func (c *Ctx) View(filename string, optionalViewModel ...interface{}) error
- func (c *Ctx) Write(bodies ...interface{})
- type Error
- type HTMLEngine
- func (s *HTMLEngine) AddFunc(funcName string, funcBody interface{})
- func (s *HTMLEngine) AddLayoutFunc(funcName string, funcBody interface{}) *HTMLEngine
- func (s *HTMLEngine) Delims(left, right string) *HTMLEngine
- func (s *HTMLEngine) ExecuteWriter(w io.Writer, name, layout string, bindingData interface{}) error
- func (s *HTMLEngine) Ext() string
- func (s *HTMLEngine) Funcs(funcMap template.FuncMap) *HTMLEngine
- func (s *HTMLEngine) Layout(layoutFile string) *HTMLEngine
- func (s *HTMLEngine) Load() error
- func (s *HTMLEngine) LoadTpls(tpls map[string]string) error
- func (s *HTMLEngine) Option(opt ...string) *HTMLEngine
- func (s *HTMLEngine) PageDir(path string) *HTMLEngine
- func (s *HTMLEngine) ParseTemplate(name string, contents []byte, funcs template.FuncMap) (err error)
- func (s *HTMLEngine) Reload(developmentMode bool) *HTMLEngine
- func (s *HTMLEngine) RootDir(root string) *HTMLEngine
- func (s *HTMLEngine) SetFuncs(funcMap template.FuncMap) *HTMLEngine
- type HandlebarsEngine
- func (s *HandlebarsEngine) AddFunc(funcName string, funcBody interface{})
- func (s *HandlebarsEngine) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) *HandlebarsEngine
- func (s *HandlebarsEngine) Debug(dev bool) *HandlebarsEngine
- func (s *HandlebarsEngine) ExecuteWriter(w io.Writer, filename string, layout string, bind interface{}) error
- func (s *HandlebarsEngine) Ext() string
- func (s *HandlebarsEngine) Layout(layoutFile string) *HandlebarsEngine
- func (s *HandlebarsEngine) Load() error
- func (s *HandlebarsEngine) LoadTpls(tpls map[string]string) error
- func (s *HandlebarsEngine) RegisterRender(funcName string)
- func (s *HandlebarsEngine) Reload(devMode bool) *HandlebarsEngine
- type Handler
- type Options
- type Route
- type Static
- type ViewEngine
Constants ¶
const ( MethodGet = "GET" // RFC 7231, 4.3.1 MethodHead = "HEAD" // RFC 7231, 4.3.2 MethodPost = "POST" // RFC 7231, 4.3.3 MethodPut = "PUT" // RFC 7231, 4.3.4 MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" // RFC 7231, 4.3.5 MethodConnect = "CONNECT" // RFC 7231, 4.3.6 MethodOptions = "OPTIONS" // RFC 7231, 4.3.7 MethodTrace = "TRACE" // RFC 7231, 4.3.8 )
HTTP methods were copied from net/http.
const ( MIMETextXML = "text/xml" MIMETextHTML = "text/html" MIMETextPlain = "text/plain" MIMEApplicationJSON = "application/json" MIMEApplicationJavaScript = "application/javascript" MIMEApplicationXML = "application/xml" MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types were copied from labstack/echo
const ( // Authentication HeaderAuthorization = "Authorization" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderProxyAuthorization = "Proxy-Authorization" HeaderWWWAuthenticate = "WWW-Authenticate" // Caching HeaderAge = "Age" HeaderCacheControl = "Cache-Control" HeaderClearSiteData = "Clear-Site-Data" HeaderExpires = "Expires" HeaderPragma = "Pragma" HeaderWarning = "Warning" // Client hints HeaderAcceptCH = "Accept-CH" HeaderAcceptCHLifetime = "Accept-CH-Lifetime" HeaderContentDPR = "Content-DPR" HeaderDPR = "DPR" HeaderEarlyData = "Early-Data" HeaderSaveData = "Save-Data" HeaderViewportWidth = "Viewport-Width" HeaderWidth = "Width" // Conditionals HeaderETag = "ETag" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderLastModified = "Last-Modified" HeaderVary = "Vary" // Connection management HeaderConnection = "Connection" HeaderKeepAlive = "Keep-Alive" // Content negotiation HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" // Controls HeaderCookie = "Cookie" HeaderExpect = "Expect" HeaderMaxForwards = "Max-Forwards" HeaderSetCookie = "Set-Cookie" // CORS HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderOrigin = "Origin" HeaderTimingAllowOrigin = "Timing-Allow-Origin" HeaderXPermittedCrossDomainPolicies = "X-Permitted-Cross-Domain-Policies" // Do Not Track HeaderDNT = "DNT" HeaderTk = "Tk" // Downloads HeaderContentDisposition = "Content-Disposition" // Message body information HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLength = "Content-Length" HeaderContentLocation = "Content-Location" HeaderContentType = "Content-Type" // Proxies HeaderForwarded = "Forwarded" HeaderVia = "Via" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedHost = "X-Forwarded-Host" HeaderXForwardedProto = "X-Forwarded-Proto" // Redirects HeaderLocation = "Location" // Request context HeaderFrom = "From" HeaderHost = "Host" HeaderReferer = "Referer" HeaderReferrerPolicy = "Referrer-Policy" HeaderUserAgent = "User-Agent" // Response context HeaderAllow = "Allow" HeaderServer = "Server" // Range requests HeaderAcceptRanges = "Accept-Ranges" HeaderContentRange = "Content-Range" HeaderIfRange = "If-Range" HeaderRange = "Range" // Security HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy" HeaderExpectCT = "Expect-CT" HeaderFeaturePolicy = "Feature-Policy" HeaderPublicKeyPins = "Public-Key-Pins" HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderUpgradeInsecureRequests = "Upgrade-Insecure-Requests" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXDownloadOptions = "X-Download-Options" HeaderXFrameOptions = "X-Frame-Options" HeaderXPoweredBy = "X-Powered-By" HeaderXXSSProtection = "X-XSS-Protection" // Server-sent event HeaderLastEventID = "Last-Event-ID" HeaderNEL = "NEL" HeaderPingFrom = "Ping-From" HeaderPingTo = "Ping-To" HeaderReportTo = "Report-To" // Transfer coding HeaderTE = "TE" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" // WebSockets HeaderSecWebSocketAccept = "Sec-WebSocket-Accept" HeaderSecWebSocketExtensions = "Sec-WebSocket-Extensions" HeaderSecWebSocketKey = "Sec-WebSocket-Key" HeaderSecWebSocketProtocol = "Sec-WebSocket-Protocol" HeaderSecWebSocketVersion = "Sec-WebSocket-Version" // Other HeaderAcceptPatch = "Accept-Patch" HeaderAcceptPushPolicy = "Accept-Push-Policy" HeaderAcceptSignature = "Accept-Signature" HeaderAltSvc = "Alt-Svc" HeaderDate = "Date" HeaderIndex = "Index" HeaderLargeAllocation = "Large-Allocation" HeaderLink = "Link" HeaderPushPolicy = "Push-Policy" HeaderRetryAfter = "Retry-After" HeaderServerTiming = "Server-Timing" HeaderSignature = "Signature" HeaderSignedHeaders = "Signed-Headers" HeaderSourceMap = "SourceMap" HeaderUpgrade = "Upgrade" HeaderXDNSPrefetchControl = "X-DNS-Prefetch-Control" HeaderXPingback = "X-Pingback" HeaderXRequestID = "X-Request-ID" HeaderXRequestedWith = "X-Requested-With" HeaderXRobotsTag = "X-Robots-Tag" HeaderXUACompatible = "X-UA-Compatible" )
HTTP Headers were copied from net/http.
const ( TextBlack = iota + 30 TextRed TextGreen TextYellow TextBlue TextMagenta TextCyan TextWhite )
Variables ¶
This section is empty.
Functions ¶
func ImmutableString ¶ added in v0.1.6
ImmutableString returns a immutable string with allocation
Types ¶
type Cookie ¶
type Cookie struct { Name string Value string Path string Domain string Expires time.Time Secure bool HTTPOnly bool SameSite string }
Cookie struct
type Core ¶
Core core class
func (*Core) Static ¶ added in v0.0.7
Static registers a new route with path prefix to serve static files from the provided root directory.
func (*Core) View ¶ added in v0.0.4
View executes and writes the result of a template file to the writer.
First parameter is the writer to write the parsed template. Second parameter is the relative, to templates directory, template filename, including extension. Third parameter is the layout, can be empty string. Forth parameter is the bindable data to the template, can be nil.
Use context.View to render templates to the client instead. Returns an error on failure, otherwise nil.
type Ctx ¶
type Ctx struct { *Core *fasthttp.RequestCtx *Route // contains filtered or unexported fields }
Ctx web context
func (*Ctx) Body ¶
Body contains the raw body submitted in a POST request. If a key is provided, it returns the form value 获得某个值用 c.FormValue
func (*Ctx) ClearCookie ¶
ClearCookie expires a specific cookie by key. If no key is provided it expires all cookies.
func (*Ctx) Download ¶
Download transfers the file from path as an attachment. Typically, browsers will prompt the user for download. By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog). Override this default with the filename parameter.
func (*Ctx) Fresh ¶
Fresh When the response is still “fresh” in the client’s cache true is returned, otherwise false is returned to indicate that the client cache is now stale and the full response should be sent. When a client sends the Cache-Control: no-cache request header to indicate an end-to-end reload request, this module will return false to make handling these requests transparent. https://github.com/jshttp/fresh/blob/10e0471669dbbfbfd8de65bc6efac2ddd0bfa057/index.js#L33
func (*Ctx) IPs ¶
IPs returns an string slice of IP addresses specified in the X-Forwarded-For request header.
func (*Ctx) Method ¶ added in v0.1.0
Method contains a string corresponding to the HTTP method of the request: GET, POST, PUT and so on.
func (*Ctx) RootDomain ¶ added in v0.1.7
RootDomain 获取主域名 默认2位
func (*Ctx) SaveFile ¶
func (c *Ctx) SaveFile(fileheader *multipart.FileHeader, path string) error
SaveFile saves any multipart file to disk.
func (*Ctx) Send ¶
func (c *Ctx) Send(bodies ...interface{})
Send sets the HTTP response body. The Send body can be of any type.
func (*Ctx) Subdomains ¶ added in v0.1.1
Subdomains 子域名.
type HTMLEngine ¶ added in v0.1.7
HTMLEngine contains the html view engine structure.
func HTML ¶ added in v0.1.7
func HTML(fs interface{}, extension string) *HTMLEngine
HTML creates and returns a new html view engine. The html engine used like the "html/template" standard go package but with a lot of extra features. The given "extension" MUST begin with a dot.
Usage: HTML("./views", ".html") or HTML(iris.Dir("./views"), ".html") or HTML(AssetFile(), ".html") for embedded data.
func (*HTMLEngine) AddFunc ¶ added in v0.1.7
func (s *HTMLEngine) AddFunc(funcName string, funcBody interface{})
AddFunc adds the function to the template's function map. It is legal to overwrite elements of the default actions: - url func(routeName string, args ...string) string - urlpath func(routeName string, args ...string) string - render func(fullPartialName string) (template.HTML, error). - tr func(lang, key string, args ...interface{}) string
func (*HTMLEngine) AddLayoutFunc ¶ added in v0.1.7
func (s *HTMLEngine) AddLayoutFunc(funcName string, funcBody interface{}) *HTMLEngine
AddLayoutFunc adds the function to the template's layout-only function map. It is legal to overwrite elements of the default layout actions: - yield func() (template.HTML, error) - current func() (string, error) - partial func(partialName string) (template.HTML, error) - partial_r func(partialName string) (template.HTML, error) - render func(fullPartialName string) (template.HTML, error).
func (*HTMLEngine) Delims ¶ added in v0.1.7
func (s *HTMLEngine) Delims(left, right string) *HTMLEngine
Delims sets the action delimiters to the specified strings, to be used in templates. An empty delimiter stands for the corresponding default: {{ or }}.
func (*HTMLEngine) ExecuteWriter ¶ added in v0.1.7
func (s *HTMLEngine) ExecuteWriter(w io.Writer, name, layout string, bindingData interface{}) error
ExecuteWriter executes a template and writes its result to the w writer.
func (*HTMLEngine) Ext ¶ added in v0.1.7
func (s *HTMLEngine) Ext() string
Ext returns the file extension which this view engine is responsible to render.
func (*HTMLEngine) Funcs ¶ added in v0.1.7
func (s *HTMLEngine) Funcs(funcMap template.FuncMap) *HTMLEngine
Funcs adds the elements of the argument map to the template's function map. It is legal to overwrite elements of the map. The return value is the template, so calls can be chained.
func (*HTMLEngine) Layout ¶ added in v0.1.7
func (s *HTMLEngine) Layout(layoutFile string) *HTMLEngine
Layout sets the layout template file which inside should use the {{ yield }} func to yield the main template file and optionally {{partial/partial_r/render}} to render other template files like headers and footers
The 'tmplLayoutFile' is a relative path of the templates base directory, for the template file with its extension.
Example: HTML("./templates", ".html").Layout("layouts/mainLayout.html")
// mainLayout.html is inside: "./templates/layouts/".
Note: Layout can be changed for a specific call action with the option: "layout" on the iris' context.Render function.
func (*HTMLEngine) Load ¶ added in v0.1.7
func (s *HTMLEngine) Load() error
Load parses the templates to the engine. It's also responsible to add the necessary global functions.
Returns an error if something bad happens, caller is responsible to handle that.
func (*HTMLEngine) LoadTpls ¶ added in v0.1.7
func (s *HTMLEngine) LoadTpls(tpls map[string]string) error
func (*HTMLEngine) Option ¶ added in v0.1.7
func (s *HTMLEngine) Option(opt ...string) *HTMLEngine
Option sets options for the template. Options are described by strings, either a simple string or "key=value". There can be at most one equals sign in an option string. If the option string is unrecognized or otherwise invalid, Option panics.
Known options:
missingkey: Control the behavior during execution if a map is indexed with a key that is not present in the map.
"missingkey=default" or "missingkey=invalid" The default behavior: Do nothing and continue execution. If printed, the result of the index operation is the string "<no value>". "missingkey=zero" The operation returns the zero value for the map type's element. "missingkey=error" Execution stops immediately with an error.
func (*HTMLEngine) PageDir ¶ added in v0.1.7
func (s *HTMLEngine) PageDir(path string) *HTMLEngine
PageDir PageDir
func (*HTMLEngine) ParseTemplate ¶ added in v0.1.7
func (s *HTMLEngine) ParseTemplate(name string, contents []byte, funcs template.FuncMap) (err error)
ParseTemplate adds a custom template to the root template.
func (*HTMLEngine) Reload ¶ added in v0.1.7
func (s *HTMLEngine) Reload(developmentMode bool) *HTMLEngine
Reload if set to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.
Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, no concurrent access across clients, use it only on development status. It's good to be used side by side with the https://github.com/kataras/rizla reloader for go source files.
func (*HTMLEngine) RootDir ¶ added in v0.1.7
func (s *HTMLEngine) RootDir(root string) *HTMLEngine
RootDir sets the directory to be used as a starting point to load templates from the provided file system.
func (*HTMLEngine) SetFuncs ¶ added in v0.1.7
func (s *HTMLEngine) SetFuncs(funcMap template.FuncMap) *HTMLEngine
SetFuncs overrides the template funcs with the given "funcMap".
type HandlebarsEngine ¶ added in v0.0.4
type HandlebarsEngine struct {
// contains filtered or unexported fields
}
HandlebarsEngine 引擎
func Handlebars ¶ added in v0.0.4
func Handlebars(directory, ext string) *HandlebarsEngine
Handlebars genera and return new handlebars view engine
func (*HandlebarsEngine) AddFunc ¶ added in v0.0.4
func (s *HandlebarsEngine) AddFunc(funcName string, funcBody interface{})
AddFunc adds the function to the template's function map. It is legal to overwrite elements of the default actions: - url func(routeName string, args ...string) string - urlpath func(routeName string, args ...string) string - render func(fullPartialName string) (raymond.HTML, error).
func (*HandlebarsEngine) Binary ¶ added in v0.0.4
func (s *HandlebarsEngine) Binary(assetFn func(name string) ([]byte, error), namesFn func() []string) *HandlebarsEngine
Binary optionally, use it when template files are distributed inside the app executable (.go generated files).
The assetFn and namesFn can come from the go-bindata library.
func (*HandlebarsEngine) Debug ¶ added in v0.1.6
func (s *HandlebarsEngine) Debug(dev bool) *HandlebarsEngine
Debug use debug model
func (*HandlebarsEngine) ExecuteWriter ¶ added in v0.0.4
func (s *HandlebarsEngine) ExecuteWriter(w io.Writer, filename string, layout string, bind interface{}) error
ExecuteWriter executes a template and writes its result to he w writer
func (*HandlebarsEngine) Ext ¶ added in v0.0.4
func (s *HandlebarsEngine) Ext() string
Ext returns the file extension which this view engine is responsible to render.
func (*HandlebarsEngine) Layout ¶ added in v0.0.4
func (s *HandlebarsEngine) Layout(layoutFile string) *HandlebarsEngine
Layout sets the layout template file which should use the {{ yield }} func to yield the main template file and optionally {{partial/partial_r/render}} to render other template files like headers and footers.
func (*HandlebarsEngine) Load ¶ added in v0.0.4
func (s *HandlebarsEngine) Load() error
Load parses the templates to the engine. It is responsible to add the necessary global functions.
Returns an error if something bad happens, user is responsible to catch it.
func (*HandlebarsEngine) LoadTpls ¶ added in v0.1.3
func (s *HandlebarsEngine) LoadTpls(tpls map[string]string) error
LoadTpls 载入数据库中的模版数据 if exists ignore.
func (*HandlebarsEngine) RegisterRender ¶ added in v0.1.7
func (s *HandlebarsEngine) RegisterRender(funcName string)
RegisterRender register custom method
func (*HandlebarsEngine) Reload ¶ added in v0.0.4
func (s *HandlebarsEngine) Reload(devMode bool) *HandlebarsEngine
Reload if set to true the templates are reloading on each render, use it when you're in development and you're boring of restarting the whole app when you edit a template file.
Note that if `true` is passed then only one `View -> ExecuteWriter` will be render each time, no concurrent access across clients, use it only on development status. It's good to be used side by side with the https://github.com/kataras/rizla reloader for go source files.
type Options ¶
type Options struct { Prefork bool // multiple go processes listening on the some port // ETag 发送etag ETag bool ServerName string // Fasthttp options Concurrency int // default: 256 * 1024 NoDefaultDate bool DisableKeepalive bool ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration MaxRequestBodySize int Debug bool ViewEngine ViewEngine }
Options all options
type Route ¶
type Route struct { Method string // http method Path string // original path Params []string // path params Regexp *regexp.Regexp // regexp matcher Handler func(*Ctx) // ctx handler Handlers []Handler `json:"-"` // Ctx handlers // contains filtered or unexported fields }
Route 路由