g2gin

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MiddlewareLimiter = func(conf *g2util.Config) gin.HandlerFunc {
	requestsPerSecond := conf.Viper().GetFloat64("http_server.limit")
	if requestsPerSecond < 1 {
		requestsPerSecond = float64(5)
	}
	lmt := tollbooth.NewLimiter(requestsPerSecond, nil)
	return func(c *gin.Context) {
		httpError := tollbooth.LimitByRequest(lmt, c.Writer, c.Request)
		if httpError != nil {
			lmt.ExecOnLimitReached(c.Writer, c.Request)

			JSONP(c, httpError.StatusCode, httpError.Message)
			c.Abort()
			return
		}
		c.Next()
	}
}

MiddlewareLimiter ...

Functions

func GinHandler added in v2.2.1

func GinHandler(fn interface{}) gin.HandlerFunc

GinHandler ...

func JSONP added in v2.2.1

func JSONP(c *gin.Context, code int, val ...interface{})

JSONP ...

Types

type G2gin

type G2gin struct {
	Config   *g2util.Config   `inject:""`
	AbFile   *g2util.AbFile   `inject:""`
	Graceful *g2util.Graceful `inject:""`
	// contains filtered or unexported fields
}

G2gin ...

func (*G2gin) Constructor

func (g *G2gin) Constructor()

Constructor ...

func (*G2gin) Run

func (g *G2gin) Run()

Run ...

func (*G2gin) SetJ2Service

func (g *G2gin) SetJ2Service(j2Service interface{})

SetJ2Service ...

type ItfGinRouter

type ItfGinRouter interface {
	Router(g *gin.RouterGroup)
	J2rpc(jsv j2rpc.RPCServer)
}

ItfGinRouter ...gin router interface

type JSONResponse added in v2.2.1

type JSONResponse struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

JSONResponse ...

Jump to

Keyboard shortcuts

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