xgin

package
v0.0.0-...-26e1b9e Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

README

xGin模块

xGin模块封装了gin框架,并提供熔断,限流,链路追踪,日志,鉴权等功能。

使用示例:

import (
	"gitlab.yaoxinhd.net/datalake/cato/cato-svc/boosting"
	"gitlab.yaoxinhd.net/datalake/cato/cato-svc/router"
	"gitlab.yaoxinhd.net/datalake/cato/cato-svc/service"
	"gitee.com/peyton1991/kuat/xgin"
)

func main() {
	if err := boosting.Init(); err != nil {
		return
	}

	launch()
}

func launch() {
	// 初始化gin配置
	server := xgin.New(boosting.Conf.Gin)
	service.Init()
	// 初始化路由
	router.InitRouter(server)
	// 服务监听
	server.Server.ListenAndServe()
	// 信号量监控
	xgin.SignalNotify(server)
}

Documentation

Index

Constants

View Source
const (
	Success = "S"
	Fail    = "F"
)

Variables

This section is empty.

Functions

func Debug

func Debug(config *Config) gin.HandlerFunc

func Metric

func Metric(config *Config) gin.HandlerFunc

func RateLimit

func RateLimit(config *Config) gin.HandlerFunc

func SignalNotify

func SignalNotify(srv *Server)

func SysAuth

func SysAuth(config *Config) gin.HandlerFunc

func Trace

func Trace(config *Config) gin.HandlerFunc

Types

type BaseHandler

type BaseHandler struct{}

func (*BaseHandler) ParamsException

func (h *BaseHandler) ParamsException(c *gin.Context, err error)

func (*BaseHandler) Response

func (h *BaseHandler) Response(c *gin.Context, data ...interface{})

func (*BaseHandler) ResponseList

func (h *BaseHandler) ResponseList(c *gin.Context, msg string, data ...interface{})

func (*BaseHandler) ResponseWithData

func (h *BaseHandler) ResponseWithData(c *gin.Context, data interface{})

func (*BaseHandler) ServiceException

func (h *BaseHandler) ServiceException(c *gin.Context, err error)

type Config

type Config struct {
	Address       string `json:"address" yaml:"address"`             //gin服务的启动地址
	Mode          string `json:"mode" yaml:"mode"`                   //gin的启动模式
	Debug         bool   `json:"debug" yaml:"debug"`                 //是否打印调试日志
	SecretKey     string `json:"secretKey" yaml:"secretKey"`         //内部系统调用的对称秘钥
	DisableMetric bool   `json:"disableMetric" yaml:"disableMetric"` //是否进行监控
	DisableTrace  bool   `json:"disableTrace" yaml:"disableTrace"`   //是否进行链路追踪
	RateLimit     int    `json:"rateLimit" yaml:"rateLimit"`         //限速
}

func DefaultConfig

func DefaultConfig() Config

type Context

type Context = gin.Context

type Engine

type Engine = gin.Engine

type ErrorType

type ErrorType uint64

ErrorType is an unsigned 64-bit error code as defined in the gin spec.

const (
	// ErrorTypeBind is used when Context.Bind() fails.
	ErrorTypeBind ErrorType = 1 << 63
	// ErrorTypeRender is used when Context.Render() fails.
	ErrorTypeRender ErrorType = 1 << 62
	// ErrorTypePrivate indicates a private error.
	ErrorTypePrivate ErrorType = 1 << 0
	// ErrorTypePublic indicates a public error.
	ErrorTypePublic ErrorType = 1 << 1
	// ErrorTypeAny indicates any other error.
	ErrorTypeAny ErrorType = 1<<64 - 1
	// ErrorTypeNu indicates any other error.
	ErrorTypeNu = 2
)

type Response

type Response struct {
	Flag string      `json:"flag"`
	Msg  string      `json:"msg"`
	Code string      `json:"code"`
	Data interface{} `json:"data,omitempty"`
}

type ResponseBodyWriter

type ResponseBodyWriter struct {
	gin.ResponseWriter
	Body *bytes.Buffer
}

ResponseBodyWriter 为了获取接口返回信息进行双写

func (ResponseBodyWriter) Write

func (r ResponseBodyWriter) Write(b []byte) (int, error)

type RouterGroup

type RouterGroup = gin.RouterGroup

type Server

type Server struct {
	*gin.Engine

	Server *http.Server
	// contains filtered or unexported fields
}

func New

func New(config *Config) *Server

type SysHandler

type SysHandler struct{}

func (*SysHandler) ParamsException

func (s *SysHandler) ParamsException(c *gin.Context, msg string, err error)

func (*SysHandler) Response

func (s *SysHandler) Response(c *gin.Context, data ...interface{})

func (*SysHandler) ResponseList

func (s *SysHandler) ResponseList(c *gin.Context, msg string, data ...interface{})

func (*SysHandler) ResponseWithData

func (s *SysHandler) ResponseWithData(c *gin.Context, data interface{})

func (*SysHandler) ServiceException

func (s *SysHandler) ServiceException(c *gin.Context, msg string, err error)

Jump to

Keyboard shortcuts

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