Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStatic ¶
func NewStatic(opts StaticOptions) gear.Middleware
NewStatic returns a Static middleware to serves static content from the provided root directory.
func NewTimeout ¶ added in v0.7.0
NewTimeout returns a timeout middleware with time.Duration and timeout hook.
app := gear.New()
app.Use(NewTimeout(time.Second, func(ctx *gear.Context) {
// timeout hook
ctx.Status(504)
ctx.String("Service timeout")
}))
app.Use(func(ctx *gear.Context) error {
// some process maybe timeout...
c, _ := ctx.WithTimeout(time.Second * 2)
select {
case <-ctx.Done(): // this case will always reached
case <-c.Done(): // this case maybe reached... but elapsed time should be 1 sec.
}
return nil
})
app.Use(func(ctx *gear.Context) error {
// if timeout, the rest of middleware will not run.
panic("this middleware unreachable")
})
Types ¶
type StaticOptions ¶
type StaticOptions struct {
Root string // The directory you wish to serve
Prefix string // The url prefix you wish to serve as static request, default to `'/'`.
StripPrefix bool // Strip the prefix from URL path, default to `false`.
}
StaticOptions is static middleware options
Click to show internal directories.
Click to hide internal directories.