Documentation
¶
Index ¶
- Constants
- func Black(msg string) string
- func Blue(msg string) string
- func Cyan(msg string) string
- func Green(msg 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) 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) 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) 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) 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) 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) ViewData(k string, v interface{}) error
- func (c *Ctx) Write(bodies ...interface{})
- 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) 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) 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 ¶
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) 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.
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) 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) 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
// contains filtered or unexported fields
}
Route 路由