Documentation ¶
Overview ¶
Package gh is an abbreviation of gin http.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProvideMiddleware ¶
func ProvideMiddleware(fn interface{})
ProvideMiddleware provide middleware
func ProvideRouterGroup ¶
func ProvideRouterGroup(groupName string, fn interface{})
ProvideRouterGroup define a router group and inject it into the runtime, then you can use it anywhere during the project lifecyle.
First, you need to use a function to create a `gin.RouterGroup`:
func init() { gh.ProvideRouterGroup("api", func(app *gh.App) *gin.RouterGroup { return app.Engine.Group("api") }) }
Then, you can use it anywhere with DI:
type routerParams struct { fx.In Default *gin.RouterGroup `name:"api"` } func init() { di.Invoke(func(r routerParams) { r.Default.GET("/", func(c *gin.Context) { c.Writer.WriteString("Hello, world!") }) }) }
Types ¶
type App ¶
App Global App
func (*App) ParseConfig ¶
ParseConfig parse `app` field in config file to an variable
type Binder ¶ added in v0.2.0
type Binder struct {
// contains filtered or unexported fields
}
Binder to customize.
func MustBind ¶ added in v0.2.0
func MustBind(fn interface{}) *Binder
MustBind bind given function into a gin.HandlerFunc, which can decode arguments from request and compose the invocation of the given function.
func (*Binder) HandlerFunc ¶ added in v0.2.0
func (b *Binder) HandlerFunc() gin.HandlerFunc
HandlerFunc returns composed handler function of gin.
func (*Binder) SetRespondErr ¶ added in v0.2.0
func (b *Binder) SetRespondErr(f ErrHandler) *Binder
SetRespondErr define how to respond error