middleware

package module
v0.0.0-...-5cc009d Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

gin-Middleware

cat-go在gin中使用的中单件

初始化
    r := gin.Default()
	r.Use(middleware.Cat(&cat.Options{
		AppId:      "cat-demo",
		Port:       2280,
		HttpPort:   8080,
		ServerAddr: "127.0.0.1",
	}))
http(可按示例封装)
middleware.HttpGet(cxt, "http://localhost:8084/test")
gorm
middleware.WithContextDB(cxt).Table("test").Count(&total)
redis
cache := middleware.Cache().WithContext(cxt)

Documentation

Index

Constants

View Source
const (
	CatCtx          = "cat_ctx"
	CatCtxRootTran  = "cat_root_tran"
	CatCtxRedisTran = "cat_redis_tran"
	CatCtxMysqlTran = "cat_mysql_tran"
)

Variables

This section is empty.

Functions

func AddGormCallbacks

func AddGormCallbacks(db *gorm.DB)

添加gormCallback

func Cache

func Cache() *redis.ClusterClient

func Cat

func Cat(opts *cat.Options) gin.HandlerFunc

监控与链路追踪

func HttpGet

func HttpGet(c *gin.Context, url string) string

func InitRedis

func InitRedis(c *RedisConfig) *redis.ClusterClient

func WithContextCache

func WithContextCache(ctx context.Context) *redis.ClusterClient

func WithCtxGorm

func WithCtxGorm(ctx context.Context, db *gorm.DB) *gorm.DB

将上下文应用到gorm实例

Types

type Header map[string]string

type RedisConfig

type RedisConfig struct {
	Addrs []string `json:"hosts"`
}

Jump to

Keyboard shortcuts

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