Documentation ¶
Index ¶
- Variables
- func DefaultGroup(prefix string, fn func(r *RouterGroup))
- func DefaultMiddleware(name string, fn func(app *Application))
- type Application
- func (app *Application) Address() string
- func (app *Application) AddressForLog() string
- func (app *Application) AddressHTTPS() string
- func (app *Application) AddressHTTPSForLog() string
- func (app *Application) Cache() cache.Cache
- func (app *Application) Cmd() cmd.Cmd
- func (app *Application) Cron() cron.Cron
- func (app *Application) Debug() debug.Debug
- func (app *Application) Env() env.Env
- func (app *Application) Fallback(h HandlerFunc)
- func (app *Application) I18n() i18n.I18n
- func (app *Application) IsProd() bool
- func (app *Application) JSONRPCRegistry() jsonrpcServer.Server
- func (app *Application) JobQueue() jobqueue.JobQueue
- func (app *Application) Listen(port int) error
- func (app *Application) Logger() *logger.Logger
- func (app *Application) MQ() mq.MQ
- func (app *Application) NotFound(h HandlerFunc)
- func (app *Application) PubSub() pubsub.PubSub
- func (app *Application) Run(addr ...string) (err error)
- func (app *Application) Runtime() runtime.Runtime
- func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (app *Application) SetBanner(banner string)
- func (app *Application) SetBeforeDestroy(fn func())
- func (app *Application) SetBeforeReady(fn func())
- func (app *Application) SetTLSCertLoader(loader func(sni string) (key, cert string, err error))
- func (app *Application) SetTemplates(dir string, fns ...template.FuncMap)
- type Context
- func (ctx *Context) Accept() string
- func (ctx *Context) AcceptEncoding() string
- func (ctx *Context) AcceptHTML() bool
- func (ctx *Context) AcceptJSON() bool
- func (ctx *Context) AcceptLanguage() string
- func (ctx *Context) AddHeader(key string, value string)
- func (ctx *Context) Authorization() string
- func (ctx *Context) BasicAuth() (username string, password string, ok bool)
- func (ctx *Context) BearerToken() (token string, ok bool)
- func (ctx *Context) BindBody(obj interface{}) error
- func (ctx *Context) BindForm(obj interface{}) error
- func (ctx *Context) BindHeader(obj interface{}) error
- func (ctx *Context) BindJSON(obj interface{}) (err error)
- func (ctx *Context) BindParams(obj interface{}) error
- func (ctx *Context) BindQuery(obj interface{}) error
- func (ctx *Context) BindYAML(obj interface{}) (err error)
- func (ctx *Context) Bodies() map[string]any
- func (ctx *Context) Body() body.Body
- func (ctx *Context) BodyBytes() ([]byte, error)
- func (ctx *Context) Cache() cache.Cache
- func (ctx *Context) ClientIP() string
- func (ctx *Context) CloneBody() (body io.ReadCloser, err error)
- func (ctx *Context) Cmd() cmd.Cmd
- func (ctx *Context) Concurrency(limit int) *concurrency.Concurrency
- func (ctx *Context) Connection() string
- func (ctx *Context) ContentType() string
- func (ctx *Context) Context() context.Context
- func (ctx *Context) Cookie() cookie.Cookie
- func (ctx *Context) Cookies() map[string]string
- func (ctx *Context) Cron() cron.Cron
- func (ctx *Context) Data(status int, contentType string, data []byte)
- func (ctx *Context) Debug() debug.Debug
- func (ctx *Context) Env() env.Env
- func (ctx *Context) Error(status int, message string)
- func (ctx *Context) Fail(err error, code int, message string, status ...int)
- func (ctx *Context) FailWithError(err HTTPError)
- func (ctx *Context) Fetch() *fetch.Fetch
- func (ctx *Context) File(key string) (multipart.File, *multipart.FileHeader, error)
- func (ctx *Context) Files() map[string]*multipart.FileHeader
- func (ctx *Context) Form() form.Form
- func (ctx *Context) Forms() (*safe.Map[string, any], error)
- func (ctx *Context) Get(key string) string
- func (ctx *Context) GetRawData() ([]byte, error)
- func (ctx *Context) HTML(status int, html string, data ...any)
- func (ctx *Context) Header() http.Header
- func (ctx *Context) Headers() *safe.Map[string, any]
- func (ctx *Context) Host() string
- func (ctx *Context) Hostname() string
- func (ctx *Context) I18n() i18n.I18n
- func (ctx *Context) IP() string
- func (ctx *Context) IPs() []string
- func (ctx *Context) IsConnectionUpgrade() bool
- func (ctx *Context) JSON(status int, obj interface{})
- func (ctx *Context) JobQueue() jobqueue.JobQueue
- func (ctx *Context) Jwt() jwt.Jwt
- func (ctx *Context) MQ() mq.MQ
- func (ctx *Context) Next()
- func (ctx *Context) Origin() string
- func (ctx *Context) Param() param.Param
- func (ctx *Context) Params() *safe.Map[string, any]
- func (ctx *Context) Protocol() string
- func (ctx *Context) Proxy(target string, cfg ...*proxy.SingleHostConfig)
- func (ctx *Context) PubSub() pubsub.PubSub
- func (ctx *Context) Queries() *safe.Map[string, any]
- func (ctx *Context) Query() query.Query
- func (ctx *Context) Redirect(url string, status ...int)
- func (ctx *Context) RedirectPermanent(url string)
- func (ctx *Context) RedirectPermanentWithOriginMethodAndBody(url string)
- func (ctx *Context) RedirectSeeOther(url string)
- func (ctx *Context) RedirectTemporary(url string)
- func (ctx *Context) RedirectTemporaryWithOriginMethodAndBody(url string)
- func (ctx *Context) Referrer() string
- func (ctx *Context) Render(status int, name string, data interface{})
- func (ctx *Context) RenderHTML(filepath string)
- func (ctx *Context) RenderIndexHTML(dir string)
- func (ctx *Context) RenderStatic(prefix, dir string)
- func (ctx *Context) RequestID() string
- func (ctx *Context) SSE() sse.SSE
- func (ctx *Context) SaveFile(key, path string) error
- func (ctx *Context) Session() session.Session
- func (ctx *Context) Set(key string, value string)
- func (ctx *Context) SetCacheControl(cacheControl string)
- func (ctx *Context) SetCacheControlWithMaxAge(maxAge time.Duration)
- func (ctx *Context) SetCacheControlWithNoCache()
- func (ctx *Context) SetCacheControlWithNoStore()
- func (ctx *Context) SetContentDisposition(filename string)
- func (ctx *Context) SetContentDispositionInline(filename string)
- func (ctx *Context) SetContentLocation(value string)
- func (ctx *Context) SetContentType(contentType string)
- func (ctx *Context) SetDownloadFilename(filename string)
- func (ctx *Context) SetHSTS(maxAge time.Duration)
- func (ctx *Context) SetHeader(key string, value string)
- func (ctx *Context) SetLocation(value string)
- func (ctx *Context) SetPoweredBy(value string)
- func (ctx *Context) SetXDownloadOptions(value string)
- func (ctx *Context) SetXDownloadOptionsNoOpen()
- func (ctx *Context) SetXDownloadOptionsNoSniff()
- func (ctx *Context) SetXFramOptions(value string)
- func (ctx *Context) SetXFramOptionsAllowFrom(uri string)
- func (ctx *Context) SetXFramOptionsDeny()
- func (ctx *Context) SetXFramOptionsSameOrigin()
- func (ctx *Context) SetXXSSProtection(value string)
- func (ctx *Context) SetXXSSProtectionDisable()
- func (ctx *Context) SetXXSSProtectionEnable()
- func (ctx *Context) SetXXSSProtectionReport(reportingURI string)
- func (ctx *Context) State() state.State
- func (ctx *Context) Status(status int)
- func (ctx *Context) StatusAccepted()
- func (ctx *Context) StatusAlreadyReported()
- func (ctx *Context) StatusBadGateway()
- func (ctx *Context) StatusBadRequest()
- func (ctx *Context) StatusCode() int
- func (ctx *Context) StatusConflict()
- func (ctx *Context) StatusCreated()
- func (ctx *Context) StatusExpectationFailed()
- func (ctx *Context) StatusFailedDependency()
- func (ctx *Context) StatusForbidden()
- func (ctx *Context) StatusFound()
- func (ctx *Context) StatusGatewayTimeout()
- func (ctx *Context) StatusGone()
- func (ctx *Context) StatusHTTPVersionNotSupported()
- func (ctx *Context) StatusIMUsed()
- func (ctx *Context) StatusInsufficientStorage()
- func (ctx *Context) StatusInternalServerError()
- func (ctx *Context) StatusLengthRequired()
- func (ctx *Context) StatusLocked()
- func (ctx *Context) StatusLoopDetected()
- func (ctx *Context) StatusMethodNotAllowed()
- func (ctx *Context) StatusMisdirectedRequest()
- func (ctx *Context) StatusMovedPermanently()
- func (ctx *Context) StatusMultiStatus()
- func (ctx *Context) StatusMultipleChoices()
- func (ctx *Context) StatusNetworkAuthenticationRequired()
- func (ctx *Context) StatusNoContent()
- func (ctx *Context) StatusNonAuthoritativeInfo()
- func (ctx *Context) StatusNotAcceptable()
- func (ctx *Context) StatusNotExtended()
- func (ctx *Context) StatusNotFound()
- func (ctx *Context) StatusNotImplemented()
- func (ctx *Context) StatusNotModified()
- func (ctx *Context) StatusOK()
- func (ctx *Context) StatusPartialContent()
- func (ctx *Context) StatusPaymentRequired()
- func (ctx *Context) StatusPermanentRedirect()
- func (ctx *Context) StatusPreconditionFailed()
- func (ctx *Context) StatusPreconditionRequired()
- func (ctx *Context) StatusProxyAuthRequired()
- func (ctx *Context) StatusRequestEntityTooLarge()
- func (ctx *Context) StatusRequestHeaderFieldsTooLarge()
- func (ctx *Context) StatusRequestTimeout()
- func (ctx *Context) StatusRequestURITooLong()
- func (ctx *Context) StatusRequestedRangeNotSatisfiable()
- func (ctx *Context) StatusResetContent()
- func (ctx *Context) StatusSeeOther()
- func (ctx *Context) StatusServiceUnavailable()
- func (ctx *Context) StatusTeapot()
- func (ctx *Context) StatusTemporaryRedirect()
- func (ctx *Context) StatusTooEarly()
- func (ctx *Context) StatusTooManyRequests()
- func (ctx *Context) StatusUnauthorized()
- func (ctx *Context) StatusUnavailableForLegalReasons()
- func (ctx *Context) StatusUnprocessableEntity()
- func (ctx *Context) StatusUnsupportedMediaType()
- func (ctx *Context) StatusUpgradeRequired()
- func (ctx *Context) StatusUseProxy()
- func (ctx *Context) StatusVariantAlsoNegotiates()
- func (ctx *Context) Stream() io.ReadCloser
- func (ctx *Context) String(status int, format string, values ...interface{})
- func (ctx *Context) Success(result interface{})
- func (ctx *Context) Template(status int, opts ...TemplateOption)
- func (ctx *Context) URL() string
- func (ctx *Context) Upgrade() string
- func (ctx *Context) User() user.User
- func (ctx *Context) UserAgent() string
- func (ctx *Context) Write(b []byte)
- func (ctx *Context) XForwardedFor() string
- func (ctx *Context) XForwardedHost() string
- func (ctx *Context) XForwardedPort() string
- func (ctx *Context) XForwardedProto() string
- func (ctx *Context) XRealIP() string
- type GroupFunc
- type H
- type HTTPError
- type HandlerFunc
- type JSONRPCHandlerFunc
- type Middleware
- type ProxyConfig
- type ResponseWriter
- type RouterGroup
- func (g *RouterGroup) Any(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Connect(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Delete(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Get(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Group(prefix string, cb ...GroupFunc) *RouterGroup
- func (g *RouterGroup) Head(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) JSONRPC(path string, handler JSONRPCHandlerFunc) *RouterGroup
- func (g *RouterGroup) Options(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Patch(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Post(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Proxy(path, target string, options ...func(cfg *ProxyConfig)) *RouterGroup
- func (g *RouterGroup) Put(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Static(basePath string, rootDir string, options ...*StaticOptions)
- func (g *RouterGroup) StaticFS(relativePath string, fs http.FileSystem)
- func (g *RouterGroup) Use(middlewares ...HandlerFunc)
- func (g *RouterGroup) WebSocket(path string, opts ...func(opt *WebSocketOption)) (websocket.Server, error)
- type StaticOptions
- type TemplateConfig
- type TemplateOption
- type WebSocketOption
- type WsHandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ( BuiltInEnvPort = "PORT" BuiltInEnvHTTPSPort = "HTTPS_PORT" BuiltInEnvMode = "MODE" BuiltInEnvLogLevel = "LOG_LEVEL" BuiltInEnvSecretKey = "SECRET_KEY" BuiltInEnvSessionMaxAge = "SESSION_MAX_AGE" BuiltInEnvRedisHost = "REDIS_HOST" BuiltInEnvRedisPort = "REDIS_PORT" BuiltInEnvRedisUser = "REDIS_USER" BuiltInEnvRedisPass = "REDIS_PASS" BuiltInEnvRedisDB = "REDIS_DB" BuiltInEnvMonitorPrometheusEnabled = "MONITOR_PROMETHEUS_ENABLED" BuiltInEnvMonitorPrometheusPath = "MONITOR_PROMETHEUS_PATH" BuiltInEnvMonitorSentryEnabled = "MONITOR_SENTRY_ENABLED" BuiltInEnvMonitorSentryDSN = "MONITOR_SENTRY_DSN" BuiltInEnvMonitorSentryDebug = "MONITOR_SENTRY_DEBUG" BuiltInEnvMonitorSentryRepanic = "MONITOR_SENTRY_REPANIC" BuiltInEnvMonitorSentryWaitForDelivery = "MONITOR_SENTRY_WAIT_FOR_DELIVERY" BuiltInEnvMonitorSentryTimeout = "MONITOR_SENTRY_TIMEOUT" )
BuiltInEnv is the built-in environment variable.
var DefaultGroupsFns = map[string]func(r *RouterGroup){}
DefaultGroupsFns ...
var DefaultMiddlewares = map[string]func(app *Application){}
DefaultMiddlewares is the default global middleware
var DefaultSecretKey = random.String(16)
DefaultSecretKey uses for session encryption and decryption.
var DefaultSessionMaxAge = 1 * 24 * time.Hour
DefaultSessionMaxAge is the default session max age.
var Version = "1.15.18"
Version is the current version of the package.
Functions ¶
func DefaultGroup ¶ added in v1.0.16
func DefaultGroup(prefix string, fn func(r *RouterGroup))
DefaultGroup ...
func DefaultMiddleware ¶ added in v1.0.16
func DefaultMiddleware(name string, fn func(app *Application))
DefaultMiddleware ...
Types ¶
type Application ¶
type Application struct { *RouterGroup // Config config.Config // contains filtered or unexported fields }
Application is the handler for all requests.
func (*Application) AddressForLog ¶ added in v1.7.12
func (app *Application) AddressForLog() string
AddressForLog ...
func (*Application) AddressHTTPS ¶ added in v1.14.3
func (app *Application) AddressHTTPS() string
AddressHTTPS ...
func (*Application) AddressHTTPSForLog ¶ added in v1.14.3
func (app *Application) AddressHTTPSForLog() string
AddressHTTPSForLog ...
func (*Application) Fallback ¶
func (app *Application) Fallback(h HandlerFunc)
Fallback is the default handler for all requests.
func (*Application) IsProd ¶ added in v1.1.0
func (app *Application) IsProd() bool
IsProd returns true if the app is in production mode.
func (*Application) JSONRPCRegistry ¶ added in v1.10.24
func (app *Application) JSONRPCRegistry() jsonrpcServer.Server
JSONRPCRegistry get a new JSONRPCRegistry handler.
func (*Application) JobQueue ¶ added in v1.9.9
func (app *Application) JobQueue() jobqueue.JobQueue
JobQueue ...
func (*Application) Listen ¶ added in v1.14.26
func (app *Application) Listen(port int) error
Listen defines the method to start the server
just like Run, but the port is required
func (*Application) Logger ¶ added in v1.0.28
func (app *Application) Logger() *logger.Logger
Logger ...
func (*Application) MQ ¶ added in v1.12.26
func (app *Application) MQ() mq.MQ
MQ get a new MQ handler.
func (*Application) NotFound ¶
func (app *Application) NotFound(h HandlerFunc)
NotFound defines the 404 handler, replaced of built in not found handler.
func (*Application) PubSub ¶ added in v1.10.21
func (app *Application) PubSub() pubsub.PubSub
PubSub get a new PubSub handler.
func (*Application) Run ¶
func (app *Application) Run(addr ...string) (err error)
Run defines the method to start the server Example:
IP: default(http://0.0.0.0:8080): Run(":8080") port(http://0.0.0.0:8888): Run(":8888") host+port(http://127.0.0.1:8888): Run("127.0.0.1:8888") HTTP: scheme://host+port(http://127.0.0.1:8888): Run("http://127.0.0.1:8888") Unix Domain Socket: /tmp/xxx.sock: Run("unix:///tmp/xxx.sock")
func (*Application) Runtime ¶ added in v1.10.3
func (app *Application) Runtime() runtime.Runtime
Runtime ...
func (*Application) ServeHTTP ¶
func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Application) SetBanner ¶ added in v1.14.3
func (app *Application) SetBanner(banner string)
SetBanner sets the banner
func (*Application) SetBeforeDestroy ¶ added in v1.14.7
func (app *Application) SetBeforeDestroy(fn func())
SetBeforeDestroy sets the before destroy method
func (*Application) SetBeforeReady ¶ added in v1.14.7
func (app *Application) SetBeforeReady(fn func())
SetBeforeReady sets the before ready method
func (*Application) SetTLSCertLoader ¶ added in v1.13.12
func (app *Application) SetTLSCertLoader(loader func(sni string) (key, cert string, err error))
SetTLSCertLoader set the tls cert loader
func (*Application) SetTemplates ¶
func (app *Application) SetTemplates(dir string, fns ...template.FuncMap)
SetTemplates set the template
type Context ¶
type Context struct { // Writer is the response writer. Writer ResponseWriter // Request is the original request object. Request *http.Request // Request is the alias of Writer. Response ResponseWriter // request Method string Path string // App *Application // Logger *logger.Logger // contains filtered or unexported fields }
Context is the request context
func (*Context) AcceptEncoding ¶ added in v1.6.12
AcceptEncoding returns the request accept header.
func (*Context) AcceptHTML ¶ added in v1.3.12
AcceptHTML returns true if the request accepts html.
func (*Context) AcceptJSON ¶ added in v1.0.19
AcceptJSON returns true if the request accepts json.
func (*Context) AcceptLanguage ¶ added in v1.6.12
AcceptLanguage returns the request accept header.
func (*Context) Authorization ¶ added in v1.3.16
Authorization returns the authorization header for auth.
func (*Context) BasicAuth ¶ added in v1.0.1
BasicAuth returns the user/password pair for Basic Authentication.
func (*Context) BearerToken ¶ added in v1.3.16
BearerToken returns the token for bearer authentication.
func (*Context) BindHeader ¶ added in v1.0.1
BindHeader binds the header into the given struct.
func (*Context) BindParams ¶ added in v1.0.1
BindParams binds the params into the given struct.
func (*Context) CloneBody ¶ added in v1.8.1
func (ctx *Context) CloneBody() (body io.ReadCloser, err error)
CloneBody clones the body of the request, should be used carefully.
func (*Context) Concurrency ¶ added in v1.11.4
func (ctx *Context) Concurrency(limit int) *concurrency.Concurrency
Concurrency creates a concurrency.
func (*Context) Connection ¶ added in v1.7.14
Connection return the request connection header.
func (*Context) ContentType ¶ added in v1.12.19
ContentType return the request content-type header.
func (*Context) Data ¶ added in v1.2.19
Data writes some data into the body stream and updates the HTTP code. Align to gin framework.
func (*Context) Error ¶
Error writes the given error to the response. Use for system errors
- Internal server error
- Not found
func (*Context) Fail ¶
Fail writes the given error with code-message-result specification to the response.
func (*Context) FailWithError ¶ added in v1.1.0
FailWithError writes the given error with code-message-result specification to the response.
func (*Context) Files ¶ added in v1.0.1
func (ctx *Context) Files() map[string]*multipart.FileHeader
Files gets all files.
func (*Context) GetRawData ¶ added in v1.2.19
GetRawData returns stream data. Align to gin framework.
func (*Context) Hostname ¶ added in v1.5.7
Hostname gets the hostname from HTTP Header. format: `hostname`
func (*Context) IP ¶ added in v1.0.4
IP gets the ip from X-Forwarded-For or X-Real-IP or RemoteIP. RemoteIP parses the IP from Request.RemoteAddr, normializes and returns the IP (without the port).
func (*Context) IPs ¶ added in v1.14.19
IPs gets the ip from X-Forwarded-For or X-Real-IP or RemoteIP. RemoteIP parses the IP from Request.RemoteAddr, normializes and returns the IP (without the port).
func (*Context) IsConnectionUpgrade ¶ added in v1.7.14
IsConnectionUpgrade checks if the connection upgrade.
func (*Context) Next ¶
func (ctx *Context) Next()
Next runs the next handler in the middleware stack
func (*Context) Proxy ¶ added in v1.8.0
func (ctx *Context) Proxy(target string, cfg ...*proxy.SingleHostConfig)
Proxy customize the request to proxy the backend services.
func (*Context) RedirectPermanent ¶ added in v1.12.19
RedirectPermanent redirects the request permanently to the given URL.
func (*Context) RedirectPermanentWithOriginMethodAndBody ¶ added in v1.12.19
RedirectPermanentWithOriginMethodAndBody redirects the request permanently to the given URL with the origin method.
func (*Context) RedirectSeeOther ¶ added in v1.12.19
RedirectSeeOther redirects the request to the given URL.
func (*Context) RedirectTemporary ¶ added in v1.12.19
RedirectTemporary redirects the request temporarily to the given URL.
func (*Context) RedirectTemporaryWithOriginMethodAndBody ¶ added in v1.12.19
RedirectTemporaryWithOriginMethodAndBody redirects the request temporarily to the given URL with the origin method.
func (*Context) RenderHTML ¶ added in v1.11.8
RenderHTML renders a template with data and writes the result to the response.
func (*Context) RenderIndexHTML ¶ added in v1.11.8
RenderIndexHTML renders the index.html file from the static directory.
func (*Context) RenderStatic ¶ added in v1.11.8
RenderStatic renders the static file from the static directory.
func (*Context) SetCacheControl ¶ added in v1.12.19
SetCacheControl sets the request cache-control header.
func (*Context) SetCacheControlWithMaxAge ¶ added in v1.12.19
SetCacheControlWithMaxAge sets the request cache-control header with max-age.
func (*Context) SetCacheControlWithNoCache ¶ added in v1.12.19
func (ctx *Context) SetCacheControlWithNoCache()
SetCacheControlWithNoCache sets the request cache-control header with no-cache.
func (*Context) SetCacheControlWithNoStore ¶ added in v1.12.19
func (ctx *Context) SetCacheControlWithNoStore()
SetCacheControlWithNoStore sets the request cache-control header with no-store.
func (*Context) SetContentDisposition ¶ added in v1.12.19
SetContentDisposition sets the request content-disposition header with attachment.
func (*Context) SetContentDispositionInline ¶ added in v1.12.19
SetContentDispositionInline sets the request content-disposition header with inline.
func (*Context) SetContentLocation ¶ added in v1.12.19
SetContentLocation sets the request content-location header.
func (*Context) SetContentType ¶ added in v1.12.19
SetContentType sets the request content-type header.
func (*Context) SetDownloadFilename ¶ added in v1.12.19
SetDownloadFilename sets the request content-disposition header with attachment and filename.
func (*Context) SetHSTS ¶ added in v1.12.19
SetHSTS sets the request strict-transport-security header.
func (*Context) SetLocation ¶ added in v1.12.19
SetLocation sets the request location header.
func (*Context) SetPoweredBy ¶ added in v1.12.19
SetPoweredBy sets the request x-powered-by header.
func (*Context) SetXDownloadOptions ¶ added in v1.12.19
SetXDownloadOptions sets the request x-download-options header.
func (*Context) SetXDownloadOptionsNoOpen ¶ added in v1.12.19
func (ctx *Context) SetXDownloadOptionsNoOpen()
SetXDownloadOptionsNoOpen sets the request x-download-options header with noopen.
func (*Context) SetXDownloadOptionsNoSniff ¶ added in v1.12.19
func (ctx *Context) SetXDownloadOptionsNoSniff()
SetXDownloadOptionsNoSniff sets the request x-download-options header with nosniff.
func (*Context) SetXFramOptions ¶ added in v1.12.19
SetXFramOptions sets the request x-frame-options header.
func (*Context) SetXFramOptionsAllowFrom ¶ added in v1.12.19
SetXFramOptionsAllowFrom sets the request x-frame-options header with allow-from.
func (*Context) SetXFramOptionsDeny ¶ added in v1.12.19
func (ctx *Context) SetXFramOptionsDeny()
SetXFramOptionsDeny sets the request x-frame-options header with deny.
func (*Context) SetXFramOptionsSameOrigin ¶ added in v1.12.19
func (ctx *Context) SetXFramOptionsSameOrigin()
SetXFramOptionsSameOrigin sets the request x-frame-options header with sameorigin.
func (*Context) SetXXSSProtection ¶ added in v1.12.19
SetXXSSProtection sets the request x-xss-protection header.
func (*Context) SetXXSSProtectionDisable ¶ added in v1.12.19
func (ctx *Context) SetXXSSProtectionDisable()
SetXXSSProtectionDisable sets the request x-xss-protection header with 0.
func (*Context) SetXXSSProtectionEnable ¶ added in v1.12.19
func (ctx *Context) SetXXSSProtectionEnable()
SetXXSSProtectionEnable sets the request x-xss-protection header with 1; mode=block.
func (*Context) SetXXSSProtectionReport ¶ added in v1.12.19
SetXXSSProtectionReport sets the request x-xss-protection header with 1; report=<reporting-uri>.
func (*Context) StatusAccepted ¶ added in v1.12.19
func (ctx *Context) StatusAccepted()
StatusAccepted sets the response status code to 202.
func (*Context) StatusAlreadyReported ¶ added in v1.12.19
func (ctx *Context) StatusAlreadyReported()
StatusAlreadyReported sets the response status code to 208.
func (*Context) StatusBadGateway ¶ added in v1.12.19
func (ctx *Context) StatusBadGateway()
StatusBadGateway sets the response status code to 502.
func (*Context) StatusBadRequest ¶ added in v1.12.19
func (ctx *Context) StatusBadRequest()
StatusBadRequest sets the response status code to 400.
func (*Context) StatusCode ¶
StatusCode returns the HTTP response status code.
func (*Context) StatusConflict ¶ added in v1.12.19
func (ctx *Context) StatusConflict()
StatusConflict sets the response status code to 409.
func (*Context) StatusCreated ¶ added in v1.12.19
func (ctx *Context) StatusCreated()
StatusCreated sets the response status code to 201.
func (*Context) StatusExpectationFailed ¶ added in v1.12.19
func (ctx *Context) StatusExpectationFailed()
StatusExpectationFailed sets the response status code to 417.
func (*Context) StatusFailedDependency ¶ added in v1.12.19
func (ctx *Context) StatusFailedDependency()
StatusFailedDependency sets the response status code to 424.
func (*Context) StatusForbidden ¶ added in v1.12.19
func (ctx *Context) StatusForbidden()
StatusForbidden sets the response status code to 403.
func (*Context) StatusFound ¶ added in v1.12.19
func (ctx *Context) StatusFound()
StatusFound sets the response status code to 302.
func (*Context) StatusGatewayTimeout ¶ added in v1.12.19
func (ctx *Context) StatusGatewayTimeout()
StatusGatewayTimeout sets the response status code to 504.
func (*Context) StatusGone ¶ added in v1.12.19
func (ctx *Context) StatusGone()
StatusGone sets the response status code to 410.
func (*Context) StatusHTTPVersionNotSupported ¶ added in v1.12.19
func (ctx *Context) StatusHTTPVersionNotSupported()
StatusHTTPVersionNotSupported sets the response status code to 505.
func (*Context) StatusIMUsed ¶ added in v1.12.19
func (ctx *Context) StatusIMUsed()
StatusIMUsed sets the response status code to 226.
func (*Context) StatusInsufficientStorage ¶ added in v1.12.19
func (ctx *Context) StatusInsufficientStorage()
StatusInsufficientStorage sets the response status code to 507.
func (*Context) StatusInternalServerError ¶ added in v1.12.19
func (ctx *Context) StatusInternalServerError()
StatusInternalServerError sets the response status code to 500.
func (*Context) StatusLengthRequired ¶ added in v1.12.19
func (ctx *Context) StatusLengthRequired()
StatusLengthRequired sets the response status code to 411.
func (*Context) StatusLocked ¶ added in v1.12.19
func (ctx *Context) StatusLocked()
StatusLocked sets the response status code to 423.
func (*Context) StatusLoopDetected ¶ added in v1.12.19
func (ctx *Context) StatusLoopDetected()
StatusLoopDetected sets the response status code to 508.
func (*Context) StatusMethodNotAllowed ¶ added in v1.12.19
func (ctx *Context) StatusMethodNotAllowed()
StatusMethodNotAllowed sets the response status code to 405.
func (*Context) StatusMisdirectedRequest ¶ added in v1.12.19
func (ctx *Context) StatusMisdirectedRequest()
StatusMisdirectedRequest sets the response status code to 421.
func (*Context) StatusMovedPermanently ¶ added in v1.12.19
func (ctx *Context) StatusMovedPermanently()
StatusMovedPermanently sets the response status code to 301.
func (*Context) StatusMultiStatus ¶ added in v1.12.19
func (ctx *Context) StatusMultiStatus()
StatusMultiStatus sets the response status code to 207.
func (*Context) StatusMultipleChoices ¶ added in v1.12.19
func (ctx *Context) StatusMultipleChoices()
StatusMultipleChoices sets the response status code to 300.
func (*Context) StatusNetworkAuthenticationRequired ¶ added in v1.12.19
func (ctx *Context) StatusNetworkAuthenticationRequired()
StatusNetworkAuthenticationRequired sets the response status code to 511.
func (*Context) StatusNoContent ¶ added in v1.12.19
func (ctx *Context) StatusNoContent()
StatusNoContent sets the response status code to 204.
func (*Context) StatusNonAuthoritativeInfo ¶ added in v1.12.19
func (ctx *Context) StatusNonAuthoritativeInfo()
StatusNonAuthoritativeInfo sets the response status code to 203.
func (*Context) StatusNotAcceptable ¶ added in v1.12.19
func (ctx *Context) StatusNotAcceptable()
StatusNotAcceptable sets the response status code to 406.
func (*Context) StatusNotExtended ¶ added in v1.12.19
func (ctx *Context) StatusNotExtended()
StatusNotExtended sets the response status code to 510.
func (*Context) StatusNotFound ¶ added in v1.12.19
func (ctx *Context) StatusNotFound()
StatusNotFound sets the response status code to 404.
func (*Context) StatusNotImplemented ¶ added in v1.12.19
func (ctx *Context) StatusNotImplemented()
StatusNotImplemented sets the response status code to 501.
func (*Context) StatusNotModified ¶ added in v1.12.19
func (ctx *Context) StatusNotModified()
StatusNotModified sets the response status code to 304.
func (*Context) StatusOK ¶ added in v1.12.19
func (ctx *Context) StatusOK()
StatusOK sets the response status code to 200.
func (*Context) StatusPartialContent ¶ added in v1.12.19
func (ctx *Context) StatusPartialContent()
StatusPartialContent sets the response status code to 206.
func (*Context) StatusPaymentRequired ¶ added in v1.12.19
func (ctx *Context) StatusPaymentRequired()
StatusPaymentRequired sets the response status code to 402.
func (*Context) StatusPermanentRedirect ¶ added in v1.12.19
func (ctx *Context) StatusPermanentRedirect()
StatusPermanentRedirect sets the response status code to 308.
func (*Context) StatusPreconditionFailed ¶ added in v1.12.19
func (ctx *Context) StatusPreconditionFailed()
StatusPreconditionFailed sets the response status code to 412.
func (*Context) StatusPreconditionRequired ¶ added in v1.12.19
func (ctx *Context) StatusPreconditionRequired()
StatusPreconditionRequired sets the response status code to 428.
func (*Context) StatusProxyAuthRequired ¶ added in v1.12.19
func (ctx *Context) StatusProxyAuthRequired()
StatusProxyAuthRequired sets the response status code to 407.
func (*Context) StatusRequestEntityTooLarge ¶ added in v1.12.19
func (ctx *Context) StatusRequestEntityTooLarge()
StatusRequestEntityTooLarge sets the response status code to 413.
func (*Context) StatusRequestHeaderFieldsTooLarge ¶ added in v1.12.19
func (ctx *Context) StatusRequestHeaderFieldsTooLarge()
StatusRequestHeaderFieldsTooLarge sets the response status code to 431.
func (*Context) StatusRequestTimeout ¶ added in v1.12.19
func (ctx *Context) StatusRequestTimeout()
StatusRequestTimeout sets the response status code to 408.
func (*Context) StatusRequestURITooLong ¶ added in v1.12.19
func (ctx *Context) StatusRequestURITooLong()
StatusRequestURITooLong sets the response status code to 414.
func (*Context) StatusRequestedRangeNotSatisfiable ¶ added in v1.12.19
func (ctx *Context) StatusRequestedRangeNotSatisfiable()
StatusRequestedRangeNotSatisfiable sets the response status code to 416.
func (*Context) StatusResetContent ¶ added in v1.12.19
func (ctx *Context) StatusResetContent()
StatusResetContent sets the response status code to 205.
func (*Context) StatusSeeOther ¶ added in v1.12.19
func (ctx *Context) StatusSeeOther()
StatusSeeOther sets the response status code to 303.
func (*Context) StatusServiceUnavailable ¶ added in v1.12.19
func (ctx *Context) StatusServiceUnavailable()
StatusServiceUnavailable sets the response status code to 503.
func (*Context) StatusTeapot ¶ added in v1.12.19
func (ctx *Context) StatusTeapot()
StatusTeapot sets the response status code to 418.
func (*Context) StatusTemporaryRedirect ¶ added in v1.12.19
func (ctx *Context) StatusTemporaryRedirect()
StatusTemporaryRedirect sets the response status code to 307.
func (*Context) StatusTooEarly ¶ added in v1.12.19
func (ctx *Context) StatusTooEarly()
StatusTooEarly sets the response status code to 425.
func (*Context) StatusTooManyRequests ¶ added in v1.12.19
func (ctx *Context) StatusTooManyRequests()
StatusTooManyRequests sets the response status code to 429.
func (*Context) StatusUnauthorized ¶ added in v1.12.19
func (ctx *Context) StatusUnauthorized()
StatusUnauthorized sets the response status code to 401.
func (*Context) StatusUnavailableForLegalReasons ¶ added in v1.12.19
func (ctx *Context) StatusUnavailableForLegalReasons()
StatusUnavailableForLegalReasons sets the response status code to 451.
func (*Context) StatusUnprocessableEntity ¶ added in v1.12.19
func (ctx *Context) StatusUnprocessableEntity()
StatusUnprocessableEntity sets the response status code to 422.
func (*Context) StatusUnsupportedMediaType ¶ added in v1.12.19
func (ctx *Context) StatusUnsupportedMediaType()
StatusUnsupportedMediaType sets the response status code to 415.
func (*Context) StatusUpgradeRequired ¶ added in v1.12.19
func (ctx *Context) StatusUpgradeRequired()
StatusUpgradeRequired sets the response status code to 426.
func (*Context) StatusUseProxy ¶ added in v1.12.19
func (ctx *Context) StatusUseProxy()
StatusUseProxy sets the response status code to 305.
func (*Context) StatusVariantAlsoNegotiates ¶ added in v1.12.19
func (ctx *Context) StatusVariantAlsoNegotiates()
StatusVariantAlsoNegotiates sets the response status code to 506.
func (*Context) Stream ¶ added in v1.0.1
func (ctx *Context) Stream() io.ReadCloser
Stream get the body stream.
func (*Context) Success ¶
func (ctx *Context) Success(result interface{})
Success writes the given data with code-message-result specification to the response.
func (*Context) Template ¶ added in v1.6.7
func (ctx *Context) Template(status int, opts ...TemplateOption)
Template renders the given template with the given data and writes the result
func (*Context) XForwardedFor ¶ added in v1.8.15
XForwardedFor return the request x-forwarded-for header.
func (*Context) XForwardedHost ¶ added in v1.8.15
XForwardedHost return the request x-forwarded-host header.
func (*Context) XForwardedPort ¶ added in v1.8.15
XForwardedPort return the request x-forwarded-port header.
func (*Context) XForwardedProto ¶ added in v1.8.15
XForwardedProto return the request x-forwarded-proto header.
type GroupFunc ¶ added in v1.8.2
type GroupFunc func(g *RouterGroup)
GroupFunc defines the group handler used by zoox
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
HandlerFunc defines the request handler used by zoox
func NotFound ¶
func NotFound() HandlerFunc
NotFound returns a HandlerFunc that replies with a 404 not found
func WrapF ¶ added in v1.10.8
func WrapF(handler http.HandlerFunc) HandlerFunc
WrapF wraps a http.HandlerFunc to a HandlerFunc
func WrapH ¶
func WrapH(handler http.Handler) HandlerFunc
WrapH wraps a http.Handler to a HandlerFunc
type JSONRPCHandlerFunc ¶ added in v1.10.23
type JSONRPCHandlerFunc func(registry jsonrpcServer.Server)
JSONRPCHandlerFunc defines the jsonrpc handler used by zoox
type Middleware ¶ added in v1.0.20
type Middleware = HandlerFunc
Middleware defines the signature of the middleware function.
type ProxyConfig ¶ added in v1.10.9
type ProxyConfig struct { // internal proxy config proxy.SingleHostConfig // context proxy config OnRequestWithContext func(ctx *Context) error OnResponseWithContext func(ctx *Context) error }
ProxyConfig defines the proxy config
type ResponseWriter ¶ added in v1.0.12
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.CloseNotifier http.Flusher // Status returns the HTTP response status code of the current request. Status() int // Size returns the number of bytes already written into the response http body. // See Written() Size() int // WriteString writes the string into the response body. WriteString(string) (int, error) // Written returns true if the response body was already written. Written() bool // Pusher get the http.Pusher for server push Pusher() http.Pusher // WriteHeaderNow forces to write the http header (status code + headers). WriteHeaderNow() }
ResponseWriter ...
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is a group of routes.
func (*RouterGroup) Any ¶ added in v1.0.3
func (g *RouterGroup) Any(path string, handler ...HandlerFunc) *RouterGroup
Any defines all request methods (anyMethods)
func (*RouterGroup) Connect ¶ added in v1.5.5
func (g *RouterGroup) Connect(path string, handler ...HandlerFunc) *RouterGroup
Connect defines the method to add CONNECT request
func (*RouterGroup) Delete ¶
func (g *RouterGroup) Delete(path string, handler ...HandlerFunc) *RouterGroup
Delete defines the method to add DELETE request
func (*RouterGroup) Get ¶
func (g *RouterGroup) Get(path string, handler ...HandlerFunc) *RouterGroup
Get defines the method to add GET request
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string, cb ...GroupFunc) *RouterGroup
Group defines a new router group
func (*RouterGroup) Head ¶
func (g *RouterGroup) Head(path string, handler ...HandlerFunc) *RouterGroup
Head defines the method to add HEAD request
func (*RouterGroup) JSONRPC ¶ added in v1.10.23
func (g *RouterGroup) JSONRPC(path string, handler JSONRPCHandlerFunc) *RouterGroup
JSONRPC defines the method to add jsonrpc route
func (*RouterGroup) Options ¶ added in v1.0.3
func (g *RouterGroup) Options(path string, handler ...HandlerFunc) *RouterGroup
Options defines the method to add OPTIONS request
func (*RouterGroup) Patch ¶
func (g *RouterGroup) Patch(path string, handler ...HandlerFunc) *RouterGroup
Patch defines the method to add PATCH request
func (*RouterGroup) Post ¶
func (g *RouterGroup) Post(path string, handler ...HandlerFunc) *RouterGroup
Post defines the method to add POST request
func (*RouterGroup) Proxy ¶ added in v1.8.0
func (g *RouterGroup) Proxy(path, target string, options ...func(cfg *ProxyConfig)) *RouterGroup
Proxy defines the method to proxy the request to the backend service.
Example:
// default no rewrites app.Proxy("/httpbin", "https://httpbin.org") // custom rewrites app.Proxy("/api/v1/tasks", "http://zmicro.services.tasks:8080", func (cfg *ProxyConfig) { cfg.Rewrites = rewriter.Rewriters{ {From: "/api/v1/tasks/(.*)", To: "/$1"}, } }))
func (*RouterGroup) Put ¶
func (g *RouterGroup) Put(path string, handler ...HandlerFunc) *RouterGroup
Put defines the method to add PUT request
func (*RouterGroup) Static ¶
func (g *RouterGroup) Static(basePath string, rootDir string, options ...*StaticOptions)
Static defines the method to serve static files
func (*RouterGroup) StaticFS ¶ added in v1.0.15
func (g *RouterGroup) StaticFS(relativePath string, fs http.FileSystem)
StaticFS defines the method to serve static files
func (*RouterGroup) Use ¶
func (g *RouterGroup) Use(middlewares ...HandlerFunc)
Use adds a middleware to the group
func (*RouterGroup) WebSocket ¶ added in v1.0.28
func (g *RouterGroup) WebSocket(path string, opts ...func(opt *WebSocketOption)) (websocket.Server, error)
WebSocket defines the method to add websocket route
type StaticOptions ¶
type StaticOptions struct { Gzip bool Md5 bool CacheControl string MaxAge time.Duration Index bool Suffix string }
StaticOptions is the options for static method
type TemplateConfig ¶ added in v1.14.17
type TemplateConfig struct { // ContentType is the template content type, default is "text/plain". ContentType string `json:"content_type"` // Name is the template name. Name string `json:"name"` // Content is the template content. Content string `json:"content"` // Data is the template data. Data any `json:"data"` }
TemplateConfig is the template config.
type TemplateOption ¶ added in v1.14.17
type TemplateOption func(*TemplateConfig)
TemplateOption is the template option.
type WebSocketOption ¶ added in v1.12.33
type WebSocketOption struct { Server websocket.Server Middlewares []HandlerFunc }
WebSocketOption ...
type WsHandlerFunc ¶ added in v1.0.28
WsHandlerFunc defines the websocket handler used by zoox