route

package
v0.0.0-...-6060d2f Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(req interface{}) (resp interface{}, err error)

type Middle

type Middle struct {
	H Handler
	V interface{}
}

Middle middleware is pre or after handler for common logic for concrete logic H is the middleware handler, handler's resp tag `plate:"x,mid"` means resp will pass this value to parser's mid view V is Handler request concrete type

type Recover

type Recover func(recV interface{}, req *http.Request, args []interface{}) (resp interface{}, err error)

Recover is function when handle panic will recover the handle controller function recV is recover() return value which catch from panic req means handle http request args means handle args and the middleware args and args are array by called sequence

type Router

type Router interface {
	// Handle register a new handle logic for given path, method and object v
	// v must be a struct or struct pointer
	Handle(method, path string, handler Handler, v interface{})
	// Sub return the relative sub router, sub router will inherit parent router's middleware
	Sub(relativePath string) Router
	// AddMiddleBefore will add mid handler before handle's handler called, v is mid request
	// v must be a struct or struct pointer
	// sub before middle exec after parent before middles
	AddMiddleBefore(mid Handler, v interface{})
	// AddMiddleAfter will add mid handler before handle's handler called, v is mid request
	// v must be a struct or struct pointer
	// sub after middle exec before parent after middles
	AddMiddleAfter(mid Handler, v interface{})
	// SetRecover set router default recover
	SetRecover(rec Recover)
	// SetAutoCors set router auto add cors methods
	SetAutoCors(bool)
	// Wait will wait all the connection logic close or timeout
	Wait(timeout int)
	// Close will close the router later connection will get failed
	Close()

	Get(path string, handler Handler, req interface{})
	Head(path string, handler Handler, req interface{})
	Post(path string, handler Handler, req interface{})
	Put(path string, handler Handler, req interface{})
	Patch(path string, handler Handler, req interface{})
	Delete(path string, handler Handler, req interface{})
	Connect(path string, handler Handler, req interface{})
	Options(path string, handler Handler, req interface{})
	Trace(path string, handler Handler, req interface{})
}

type Server

type Server interface {
	// Route return server root route
	Route() Router
	// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
	// Note: this method will block the calling goroutine indefinitely unless an error happens.
	Run(addr ...string)
	// Close the server close, after this method called all request all failed with 500 status code
	Close()
	// Wait all server request handle event finish or timeout
	Wait(timeout int)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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