gh

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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