fgin

package module
v0.0.0-...-2d2e4ec Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

读取配置文件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayFindString

func ArrayFindString(search []string, flag string) bool

查看数组内是否有

func FbindParams

func FbindParams(ctx *gin.Context, input interface{}) error

绑定参数,利用的gin的bind逻辑,可返回自定义错误

func GenToken

func GenToken(authData map[string]string) (string, error)

func GetGrpcClientConn

func GetGrpcClientConn(serviceName, tag string) (*grpc.ClientConn, error)

该方法用于需要关闭conn的时候使用

func GetGrpcCtx

func GetGrpcCtx(ctx *gin.Context) context.Context

生成新context,自动植入grpc的信息

func ParsearseToken

func ParsearseToken(tokenStr string) (*customClaims, error)

func ReturnJson

func ReturnJson(ctx *gin.Context, code int, data any, err error)

返回数据

Types

type Auth

type Auth struct {
	AuthLs        []string `json:"auth_ls" mapstructure:"auth_ls"`
	Timeout       int      `json:"time_out" mapstructure:"time_out"`
	SecreKey      string   `json:"secre_key" mapstructure:"secre_key"`
	SigningMethod int      `json:"signing_method" mapstructure:"signing_method"`
	HeaderKey     string   `json:"header_key" mapstructure:"header_key"`
	DisableLs     []string `json:"disable_ls" mapstructure:"disable_ls"`
}

type Config

type Config struct {
	ServiceName string       `yaml:"service_name" mapstructure:"service_name"`
	Tag         string       `yaml:"tag" mapstructure:"tag"`
	NetType     string       `yaml:"net_type" mapstructure:"net_type"`
	Ip          string       `yaml:"ip" mapstructure:"ip"`
	Port        int          `yaml:"port" mapstructure:"port"`
	Env         string       `yaml:"env" mapstructure:"env"`
	Log         Log          `yaml:"log" mapstructure:"log"`
	Auth        Auth         `yaml:"auth" mapstructure:"auth"`
	Mysql       []Mysql      `yaml:"mysql" mapstructure:"mysql"`
	GormLog     GormLog      `yaml:"gorm_log" mapstructure:"gorm_log"`
	Redis       Redis        `yaml:"redis" mapstructure:"redis"`
	Consul      Consul       `yaml:"consul" mapstructure:"consul"`
	Jaeger      Jaeger       `yaml:"jaeger" mapstructure:"jaeger"`
	Rabbitmq    []Rabbitmq   `yaml:"rabbitmq" mapstructure:"rabbitmq"`
	GrpcClient  []GrpcClient `yaml:"grpc_client" mapstructure:"grpc_client"`
	Cors        Cors         `yaml:"cors" mapstructure:"cors"`
}

type Consul

type Consul struct {
	Address string `yaml:"address" mapstructure:"address"`
	Token   string `yaml:"token" mapstructure:"token"`
}

type Cors

type Cors struct {
	UseDefault       bool   `yaml:"use_default" mapstructure:"use_default"`
	AllowOrigins     string `yaml:"allow_origins" mapstructure:"allow_origins"`
	AllowMethods     string `yaml:"allow_methods" mapstructure:"allow_methods"`
	AllowHeaders     string `yaml:"allow_headers" mapstructure:"allow_headers"`
	ExposeHeaders    string `yaml:"expose_headers" mapstructure:"expose_headers"`
	AllowCredentials bool   `yaml:"allow_credentials" mapstructure:"allow_credentials"`
	MaxAge           int    `yaml:"max_age" mapstructure:"max_age"`
}

解决跨域配置

type Fgin

type Fgin struct{}

func (*Fgin) GetConfig

func (f *Fgin) GetConfig() Config

获得config

func (*Fgin) GetFgrpcClientConn

func (f *Fgin) GetFgrpcClientConn(serviceName string) (*FgrpcClientConn, error)

获取grpc已经dail的conn

func (*Fgin) GetGormDb

func (f *Fgin) GetGormDb(name string) *gorm.DB

获得数据库连接

func (*Fgin) GetGrpcServer

func (f *Fgin) GetGrpcServer(path string) *grpc.Server

获取一个grpc服务

func (*Fgin) GetHttpServer

func (f *Fgin) GetHttpServer(path string) *gin.Engine

获取一个路由

func (*Fgin) GetLogger

func (f *Fgin) GetLogger() *zap.SugaredLogger

获得日志操作

func (*Fgin) GetRabbitmqConn

func (f *Fgin) GetRabbitmqConn(queueName string) (*amqp.Connection, error)

获取rabbitmq dail的conn

func (*Fgin) GetRedisClient

func (f *Fgin) GetRedisClient() redis.UniversalClient

获取redis连接

func (*Fgin) Run

func (f *Fgin) Run(router *gin.Engine)

优雅启动

func (*Fgin) RunGrpc

func (f *Fgin) RunGrpc(s *grpc.Server)

启动grpc服务

type FginRabbitmq

type FginRabbitmq struct {
	QueueName     string
	MaxRetry      int32
	MaxConsume    int
	RabbitmqConn  *amqp.Connection
	RabbitmqCh    []*amqp.Channel
	RabbitmqQueue *amqp.Queue
}

框架的默认队列对象

func DefaultQueue

func DefaultQueue(queueName string) (*FginRabbitmq, error)

声明默认队列

func (*FginRabbitmq) DefaultConsumer

func (fr *FginRabbitmq) DefaultConsumer(hander func(msg amqp.Delivery) error) error

默认消费者

func (*FginRabbitmq) DefaultProducter

func (fr *FginRabbitmq) DefaultProducter(contentType string, body []byte) error

默认生产者

type FgrpcClientConn

type FgrpcClientConn struct {
	*grpc.ClientConn
}

func (*FgrpcClientConn) Close

func (f *FgrpcClientConn) Close()

type GormLog

type GormLog struct {
	SlowThreshold             int  `yaml:"slow_threshold" mapstructure:"slow_threshold"`                               // 慢查询阈值,单位 ms
	Colorful                  bool `yaml:"colorful" mapstructure:"colorful"`                                           // 日志是否着色
	IgnoreRecordNotFoundError bool `yaml:"ignore_record_not_found_error" mapstructure:"ignore_record_not_found_error"` // 是否忽略记录不存在的错误
	ParameterizedQueries      bool `yaml:"parameterized_queries" mapstructure:"parameterized_queries"`                 // 不包含参数在sql log内
	LogLevel                  int  `yaml:"log_level" mapstructure:"log_level"`                                         // 1: Silent, 2: Error, 3: Warn, 4: Info
}

type GrpcClient

type GrpcClient struct {
	ServiceName string `yaml:"service_name" mapstructure:"service_name"`
	Tag         string `yaml:"tag" mapstructure:"tag"`
}

type HealthService

type HealthService struct{}

手动实现健康检查部分

func (*HealthService) Check

func (*HealthService) Watch

type Jaeger

type Jaeger struct {
	Address     string `yaml:"address" mapstructure:"address"`
	AddressHTTP string `yaml:"address_http" mapstructure:"address_http"`
}

type Log

type Log struct {
	Level     string `yaml:"level" mapstructure:"level"`
	WriteType int    `yaml:"write_type" mapstructure:"write_type"`
	LogPath   string `yaml:"log_path" mapstructure:"log_path"`
}

type Mysql

type Mysql struct {
	Name    string `yaml:"name" mapstructure:"name"`
	Target  string `yaml:"target" mapstructure:"Target"`
	MaxIdle int    `yaml:"max_idle" mapstructure:"max_idle"`
	MaxOpen int    `yaml:"max_open" mapstructure:"max_open"`
	MaxLift int    `yaml:"max_lift" mapstructure:"max_lift"`
}

type Rabbitmq

type Rabbitmq struct {
	Address    string `yaml:"address" mapstructure:"address"`
	QueueName  string `yaml:"queue_name" mapstructure:"queue_name"`
	MaxRetry   int32  `yaml:"max_retry" mapstructure:"max_retry"`
	MaxConsume int    `yaml:"max_consume" mapstructure:"max_consume"`
}

type Redis

type Redis struct {
	Addrs      []string `yaml:"addrs" mapstructure:"addrs"` // 多个地址,使用集群模式
	UserName   string   `yaml:"user_name" mapstructure:"user_name"`
	PassWord   string   `yaml:"pass_word" mapstructure:"pass_word"`
	Db         int      `yaml:"db" mapstructure:"db"`
	MasterName string   `yaml:"master_name" mapstructure:"master_name"` // 配置name,使用哨兵模式
}

Jump to

Keyboard shortcuts

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