gh

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

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

type App struct {
	Engine *gin.Engine
	// contains filtered or unexported fields
}

App Global App

func (*App) Name

func (app *App) Name() string

Name returns app name

func (*App) ParseConfig

func (app *App) ParseConfig(ptr interface{}) error

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

func (*Binder) SetRespondOk added in v0.2.0

func (b *Binder) SetRespondOk(f func(c *gin.Context, r interface{})) *Binder

SetRespondOk define how to respond ok.

type ErrHandler added in v0.2.0

type ErrHandler func(c *gin.Context, code int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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