houyi

package module
v0.0.0-...-a9809d7 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

houyi

router with middleware

example

	y := houyi.New()
	y.
		NewLayer("a").
		Use(func(context *houyi.Context) (err error) {
			log.Println("middle 1")
			return
		}).
		Use(func(context *houyi.Context) (err error) {
			log.Println("middle 2")
			return
		}).
		NewLayer("b").
		Use(func(context *houyi.Context) (err error) {
			log.Println("middle 3")
			return
		}).
		Hit("", func(context *houyi.Context) (err error) {
			log.Println("hit")
			return
		})

	log.Println(y.Handle("a.b", []byte("data")))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrorWriter io.Writer = os.Stderr
View Source
var DefaultWriter io.Writer = os.Stdout

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Bind

func (c *Context) Bind(o interface{}) (err error)

func (*Context) BindJson

func (c *Context) BindJson(o interface{}) (err error)

func (*Context) BindProtoBuf

func (c *Context) BindProtoBuf(o proto.Message) (err error)

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) GetEnv

func (c *Context) GetEnv() interface{}

func (*Context) GetResult

func (c *Context) GetResult() []byte

func (*Context) GetUri

func (c *Context) GetUri() (data string)

func (*Context) Next

func (c *Context) Next() (err error)

func (*Context) ProtoBuf

func (c *Context) ProtoBuf(o proto.Message) (err error)

func (*Context) RawData

func (c *Context) RawData() []byte

func (*Context) SetResult

func (c *Context) SetResult(raw []byte)

func (*Context) String

func (c *Context) String() (data string)

func (*Context) Value

func (c *Context) Value(key interface{}) interface{}

type Engine

type Engine struct {
	Layer
	// contains filtered or unexported fields
}

func New

func New() *Engine

func (*Engine) Handle

func (e *Engine) Handle(uri string, data []byte, env interface{}) (result []byte, err error)

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc defines the handler used by gin middleware as return value.

func Logger

func Logger() HandlerFunc

func Recovery

func Recovery() HandlerFunc

type HandlersChain

type HandlersChain []HandlerFunc

HandlersChain defines a HandlerFunc array.

func (HandlersChain) Last

func (c HandlersChain) Last() HandlerFunc

Last returns the last handler in the chain. ie. the last handler is the main own.

type ILayer

type ILayer interface {
	Use(...HandlerFunc) ILayer
	NewLayer(string) *Layer
	Hit(string, HandlerFunc) *Layer
}

ILayer defines all router handle interface includes single and group router.

type Layer

type Layer struct {
	// contains filtered or unexported fields
}

Layer is used internally to configure router, a Layer is associated with a prefix and an array of handlers (middleware).

func (*Layer) Hit

func (l *Layer) Hit(name string, handler HandlerFunc) *Layer

func (*Layer) NewLayer

func (l *Layer) NewLayer(name string) *Layer

func (*Layer) Use

func (l *Layer) Use(handlers ...HandlerFunc) ILayer

Jump to

Keyboard shortcuts

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