middleware

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2016 License: MIT Imports: 6 Imported by: 0

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

func NewTimeout(du time.Duration, h gear.Hook) gear.Middleware

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL