Documentation
¶
Overview ¶
读取配置文件
处理用户使用自定义组件
Index ¶
- Variables
- func ArrayFindString(search []string, flag string) bool
- func DelArrItemStr(arr []string, step int) []string
- func FbindParams(ctx *gin.Context, input interface{}) error
- func FginBindPlugConfig(plugConfig any, plugObj any) error
- func FginGetPlugConfig(plugName string) (any, error)
- func FileOrDirExists(path string) bool
- 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 MakeDirAll(path string) error
- 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 ReginsterGrpcDialOptions(opts []grpc.DialOption, ...)
- 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 RegisterGrpcServerOptions(opts []grpc.ServerOption, ...)
- func ReturnJson(ctx *gin.Context, code int, data any, err error)
- func ValidateBindParams(ctx *gin.Context, input any) error
- func ValidateStruct(data any) 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) GetHttpGrpcServer(path string) (*gin.Engine, *grpc.Server)
- func (f *Fgin) GetHttpServer(path string) *gin.Engine
- func (f *Fgin) GetLogger() *zap.SugaredLogger
- func (f *Fgin) GetOtherConfig(cfg any) error
- 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)
- func (f *Fgin) RunHttpGrpc(r *gin.Engine, s *grpc.Server)
- type FginGrpcClientMiddPlugInterface
- type FginGrpcMiddPlugsInterface
- type FginGrpcPlugsInterface
- type FginHttpPlugsInterface
- type FginRabbitmq
- type FginResponseWriter
- type FginSugaredLogger
- type FgrpcClientConn
- type GormLog
- type GrpcClient
- type Jaeger
- type Log
- type Mysql
- type Prometheus
- type Rabbitmq
- type Redis
- type RestartFgrpcClient
Constants ¶
This section is empty.
Variables ¶
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 DelArrItemStr ¶
指定数组元素删除,step表示要删除的位置,-1表示末尾
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 ReginsterGrpcDialOptions ¶
func ReginsterGrpcDialOptions(opts []grpc.DialOption, disableDefaultWithTransportCredentials, disableDefaultWithUnaryInterceptor bool)
注册grpc dial options 进入框架 disableDefaultWithTransportCredentials 是否禁止框架默认安全协议 disableDefaultWithUnaryInterceptor 是否禁止使用框架自带的客户端一元拦截器。禁止会导致,框架中的请求日志、jaeger、发生异常重新微服务寻址、限流、熔断、热插拔3方插件失效。不建议禁止
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组件
func RegisterGrpcServerOptions ¶
func RegisterGrpcServerOptions(opts []grpc.ServerOption, disableDefaultTimeout, disableDefaultUnaryInterceptor bool)
注册grpc server options 进入框架 是否禁止框架自带的客户端连接超时配置 是否禁止使用框架自带的一元拦截器。禁止会导致,框架中的请求日志、jaeger、prometheus、限流、熔断、热插拔3方插件失效。不建议禁止
func ValidateBindParams ¶
绑定参数,使用validator的逻辑,可返回自定义参数名
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"`
ServiceWeight int `yaml:"service_weight" mapstructure:"service_weight"`
Ip string `yaml:"ip" mapstructure:"ip"`
Port int `yaml:"port" mapstructure:"port"`
HttpPort int `yaml:"http_port" mapstructure:"http_port"`
GrpcPort int `yaml:"grpc_port" mapstructure:"grpc_port"`
Env string `yaml:"env" mapstructure:"env"`
Timeout int `yaml:"time_out" mapstructure:"time_out"` // 请求超时时间,单位ms
DisableRequestTimeout bool `yaml:"disable_request_timeout" mapstructure:"disable_request_timeout"` // 禁止继承上游服务耗时 默认不禁止
RateLimiter bool `yaml:"rate_limiter" mapstructure:"rate_limiter"` // 限流器是否开启
CircuitBreaker bool `yaml:"circuit_breaker" mapstructure:"circuit_breaker"` // 熔断器是否开启
Validator string `yaml:"validator" mapstructure:"validator"` // 独立校验器配置
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"`
OtherConfig any `yaml:"other_config" mapstructure:"other_config"`
}
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) GetHttpGrpcServer ¶
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 ¶
func (f *Fgin) GetRedisClientByName(redisName string) (redis.UniversalClient, error)
获取redis链接 通过名称获取
type FginGrpcMiddPlugsInterface ¶
type FginGrpcMiddPlugsInterface interface {
// grpc server拦截器给到ctx
Start(ctx context.Context, req any, info *grpc.UnaryServerInfo, logger *FginSugaredLogger) (context.Context, error)
// grpc server 方法执行后
AfterStart(ctx context.Context, req any, info *grpc.UnaryServerInfo, grpcErr error, logger *FginSugaredLogger) error
}
type FginGrpcPlugsInterface ¶
type FginGrpcPlugsInterface interface {
// grpc自定义组件
Start(logger *FginSugaredLogger)
}
type FginHttpPlugsInterface ¶
type FginHttpPlugsInterface interface {
// 给到router,可以实现中间件,也可以实现其他组件
Start(router *gin.Engine, logger *FginSugaredLogger)
}
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 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"`
SkipDefaultTran bool `yaml:"skip_default_tran" mapstructure:"skip_default_tran"` // 是否禁用默认事务
PrepareStmt bool `yaml:"prepare_stmt" mapstructure:"prepare_stmt"` // 是否开启缓存已编译sql
}
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
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
demos
|
|
|
fauth_test
command
|
|
|
fconfig_test
command
|
|
|
fconsul_test/client
command
|
|
|
fconsul_test/server
command
|
|
|
fconsul_test/server1
command
|
|
|
fhttpgrpc_test
command
|
|
|
fjaeger_test/client
command
|
|
|
fjaeger_test/client1
command
|
|
|
fjaeger_test/server
command
|
|
|
fjaeger_test/server1
command
|
|
|
flog_test
command
|
|
|
fmysql_test
command
|
|
|
fplug_timeout_test/gin_timeout
command
|
|
|
fplug_timeout_test/http_timeout
command
|
|
|
fplugs_grpc_test/client
command
|
|
|
fplugs_grpc_test/server
command
|
|
|
fplugs_grpc_test/server1
command
|
|
|
fplugs_test
command
|
|
|
fprometheus_grpc_test/server
command
|
|
|
fprometheus_http_test/client
command
|
|
|
fprometheus_http_test/demo
command
|
|
|
fprometheus_http_test/metricsTry
command
|
|
|
frabbitmq_test/consumer
command
|
|
|
frabbitmq_test/product
command
|
|
|
fredis_test/grpc_demo
command
|
|
|
fredis_test/http_demo
command
|
|
|
fserver_test/bind_params_demo
command
|
|
|
fvalidator_test/grpc
command
|
|
|
fvalidator_test/http
command
|
|
|
fvalidator_test/http_grpc
command
|
|
|
plugs
|
|