Documentation ¶
Overview ¶
读取配置文件
处理用户使用自定义组件
Index ¶
- Variables
- func ArrayFindString(search []string, flag string) bool
- func FbindParams(ctx *gin.Context, input interface{}) error
- func FginBindPlugConfig(plugConfig any, plugObj any) error
- func FginGetPlugConfig(plugName string) (any, error)
- func GenToken(authData map[string]string) (string, error)
- func GetCtxToHeader(ctx context.Context) http.Header
- func GetGrpcClientConn(serviceName, tag string) (*grpc.ClientConn, error)deprecated
- func GetGrpcClientConnV2(serviceName, tag, address string) (*grpc.ClientConn, error)
- func GetGrpcCtx(ctx context.Context) context.Context
- func ParsearseToken(tokenStr string) (*customClaims, error)
- func PlugsGrpcClientMiddAfterStart(ctx context.Context, method string, req, reply any, grpcErr error) error
- func PlugsGrpcClientMiddStart(ctx context.Context, method string, req, reply any) (context.Context, error)
- func PlugsGrpcMiddAfterStart(ctx context.Context, req any, info *grpc.UnaryServerInfo, grpcErr error) error
- func PlugsGrpcMiddStart(ctx context.Context, req any, info *grpc.UnaryServerInfo) (context.Context, error)
- func PlugsGrpcStart()
- func PlugsHttpStart(router *gin.Engine)
- func RegisteGrpcClientMiddPlug(plugName string, plugObj FginGrpcClientMiddPlugInterface)
- func RegisteGrpcMiddPlug(plugName string, plugObj FginGrpcMiddPlugsInterface)
- func RegisteGrpcPlug(plugName string, plugObj FginGrpcPlugsInterface)
- func RegisteHttpPlug(plugName string, plugObj FginHttpPlugsInterface)
- func ReturnJson(ctx *gin.Context, code int, data any, err error)
- type Auth
- type Config
- type Consul
- type Cors
- type Fgin
- func (f *Fgin) GetConfig() Config
- func (f *Fgin) GetFginLogger() *FginSugaredLogger
- func (f *Fgin) GetFgrpcClientConn(serviceName string) (*FgrpcClientConn, error)
- func (f *Fgin) GetGormDb(name string) *gorm.DB
- func (f *Fgin) GetGrpcServer(path string) *grpc.Server
- func (f *Fgin) GetHttpServer(path string) *gin.Engine
- func (f *Fgin) GetLogger() *zap.SugaredLogger
- func (f *Fgin) GetRabbitmqConn(queueName string) (*amqp.Connection, error)
- func (f *Fgin) GetRedisClient() redis.UniversalClient
- func (f *Fgin) GetRedisClientByName(redisName string) (redis.UniversalClient, error)
- func (f *Fgin) Run(router *gin.Engine)
- func (f *Fgin) RunGrpc(s *grpc.Server)
- type FginGrpcClientMiddPlugInterface
- type FginGrpcMiddPlugsInterface
- type FginGrpcPlugsInterface
- type FginHttpPlugsInterface
- type FginRabbitmq
- type FginResponseWriter
- type FginSugaredLogger
- type FgrpcClientConn
- type GormLog
- type GrpcClient
- type HealthService
- type Jaeger
- type Log
- type Mysql
- type Prometheus
- type Rabbitmq
- type Redis
- type RestartFgrpcClient
Constants ¶
This section is empty.
Variables ¶
View Source
var ( FGINHTTPPLUGSMAP = map[string]FginHttpPlugsInterface{} // http自定义组件 FGINGRPCMIDDPLUGSMAP = map[string]FginGrpcMiddPlugsInterface{} // grpc server拦截器自定义组件 FGINGRPCCLIENTMIDDPLUGSMAP = map[string]FginGrpcClientMiddPlugInterface{} // grpc client端拦截器 FGINGRPCPLUGSMAP = map[string]FginGrpcPlugsInterface{} // grpc自定义组件 )
全局插件记录
Functions ¶
func FbindParams ¶
绑定参数,利用的gin的bind逻辑,可返回自定义错误 优化 支持嵌套结构体往下查找
func GetCtxToHeader ¶
将context 转为header,实现span在http协议中传送
func GetGrpcClientConn
deprecated
func GetGrpcClientConn(serviceName, tag string) (*grpc.ClientConn, error)
Deprecated: 该方法用于需要关闭conn的时候使用。已废弃,请使用兼容性更强的GetGrpcClientConnV2方法
func GetGrpcClientConnV2 ¶
func GetGrpcClientConnV2(serviceName, tag, address string) (*grpc.ClientConn, error)
该方法用于需要关闭conn的时候使用,优化方法兼容直接给grpc服务直连
func ParsearseToken ¶
func PlugsGrpcClientMiddAfterStart ¶
func PlugsGrpcClientMiddAfterStart(ctx context.Context, method string, req, reply any, grpcErr error) error
grpc client 中间件拦截器运行 运行后
func PlugsGrpcClientMiddStart ¶
func PlugsGrpcClientMiddStart(ctx context.Context, method string, req, reply any) (context.Context, error)
grpc client 中间件拦截器运行
func PlugsGrpcMiddAfterStart ¶
func PlugsGrpcMiddAfterStart(ctx context.Context, req any, info *grpc.UnaryServerInfo, grpcErr error) error
grpc拦截器自定义组件运行后 接着运行
func PlugsGrpcMiddStart ¶
func PlugsGrpcMiddStart(ctx context.Context, req any, info *grpc.UnaryServerInfo) (context.Context, error)
grpc拦截器自定义组件运行
func RegisteGrpcClientMiddPlug ¶
func RegisteGrpcClientMiddPlug(plugName string, plugObj FginGrpcClientMiddPlugInterface)
注册grpc client拦截器组件
func RegisteGrpcMiddPlug ¶
func RegisteGrpcMiddPlug(plugName string, plugObj FginGrpcMiddPlugsInterface)
注册grpc拦截器组件
func RegisteGrpcPlug ¶
func RegisteGrpcPlug(plugName string, plugObj FginGrpcPlugsInterface)
注册grpc组件
func RegisteHttpPlug ¶
func RegisteHttpPlug(plugName string, plugObj FginHttpPlugsInterface)
注册http组件
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"` RateLimiter bool `yaml:"rate_limiter" mapstructure:"rate_limiter"` // 限流器是否开启 CircuitBreaker bool `yaml:"circuit_breaker" mapstructure:"circuit_breaker"` // 熔断器是否开启 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"` Prometheus Prometheus `yaml:"prometheus" mapstructure:"prometheus"` Plugs map[string]any `yaml:"plugs" mapstructure:"plugs"` }
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) GetFgrpcClientConn ¶
func (f *Fgin) GetFgrpcClientConn(serviceName string) (*FgrpcClientConn, error)
获取grpc已经dail的conn
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) GetRedisClientByName ¶
获取redis链接 通过名称获取
type FginGrpcPlugsInterface ¶
type FginGrpcPlugsInterface interface {
// grpc自定义组件
Start()
}
type FginHttpPlugsInterface ¶
type FginRabbitmq ¶
type FginRabbitmq struct { QueueName string MaxRetry int32 MaxConsume int RabbitmqConn *amqp.Connection RabbitmqCh []*amqp.Channel RabbitmqQueue *amqp.Queue }
框架的默认队列对象
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 FginResponseWriter ¶
type FginResponseWriter struct { gin.ResponseWriter // contains filtered or unexported fields }
定义一个自定义的 ResponseWriter,以便我们可以捕获响应数据
type FginSugaredLogger ¶
type FginSugaredLogger struct {
// contains filtered or unexported fields
}
func (*FginSugaredLogger) Debug ¶
func (s *FginSugaredLogger) Debug(args ...interface{})
func (*FginSugaredLogger) Error ¶
func (s *FginSugaredLogger) Error(args ...interface{})
func (*FginSugaredLogger) Info ¶
func (s *FginSugaredLogger) Info(args ...interface{})
func (*FginSugaredLogger) Warn ¶
func (s *FginSugaredLogger) Warn(args ...interface{})
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 HealthService ¶
type HealthService struct{}
手动实现健康检查部分
func (*HealthService) Check ¶
func (s *HealthService) Check(ctx context.Context, req *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error)
func (*HealthService) Watch ¶
func (s *HealthService) Watch(req *healthpb.HealthCheckRequest, srv healthpb.Health_WatchServer) error
type Prometheus ¶
type Prometheus struct { Ip string `yaml:"ip" mapstructure:"ip"` Port int `yaml:"port" mapstructure:"port"` Path string `yaml:"path" mapstructure:"path"` }
普罗米修斯配置
type Redis ¶
type Redis struct { RedisName string `yaml:"redis_name" mapstructure:"redis_name"` // redis服务的名称,使用多个不同redis 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,使用哨兵模式 }
type RestartFgrpcClient ¶
type RestartFgrpcClient struct { ServiceName string // grpc服务名 Tag string // grpc服务tag Address string // grpc直连地址 当serviceName和tag存在的时候,可以不填 // contains filtered or unexported fields }
重新grpc conn出现断开后,可以创建一个新的
func GetRestartGrpcObj ¶
func GetRestartGrpcObj(serviceName string) (*RestartFgrpcClient, error)
获取grpc链接重启对象
func (*RestartFgrpcClient) RestartFgrpcClientConn ¶
func (r *RestartFgrpcClient) RestartFgrpcClientConn() (*FgrpcClientConn, error)
重启grpc连接方法
Source Files ¶
Click to show internal directories.
Click to hide internal directories.