Documentation ¶
Index ¶
- Constants
- Variables
- func BASE64Decode(str string) ([]byte, error)
- func BASE64DecodeStr(str string) (string, error)
- func BASE64Encode(byt []byte) string
- func BASE64EncodeStr(str string) string
- func FormatCaller(ok bool, desc string) string
- func FormatError(code Code, desc string, err error) error
- func FormatInfo(desc string) string
- func GenAppSignature(id string, secret string, userId string, nonce string) string
- func GenRSAKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)
- func GetCallerFileAndLine(level int) string
- func GetCallerInfo(level int) (string, string, int)
- func GetCallerName(level int) string
- func GetClientIP(c *gin.Context) string
- func GetEncodedPwd(pwd string) (string, string)
- func GetFuncName() string
- func GetPrivateKey() *rsa.PrivateKey
- func GetProjectPath() string
- func GetPublicKey() *rsa.PublicKey
- func GetPublicKeyStr() string
- func GetPwdEncodingOpts() *password.Options
- func GetRandomIdlePort() string
- func GetUserAgent(c *gin.Context) string
- func HmacSHA256(byt []byte, secret string) string
- func HmacSHA256Str(str string, secret string) string
- func In(haystack interface{}, needle interface{}) bool
- func InitDB() (*gorm.DB, func(), error)
- func InitGinEngine() *gin.Engine
- func InitLogger() func()
- func InitLogrus() *logrus.Logger
- func InitPrometheusRegistry() *prometheus.Registry
- func InitRedis() (*redis.Client, func(), error)
- func InitTracer() *jConfig.Configuration
- func InitVault()
- func LoadEnv() string
- func LogFailure(code Code, desc string, err error)
- func LogSuccess(desc string)
- func LoggerForHTTP() gin.HandlerFunc
- func LoggerForRPC(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (interface{}, error)
- func MD5(byt []byte) string
- func MD5Str(str string) string
- func PrivateKeyB64StrToStruct(privateKeyStr string) (*rsa.PrivateKey, error)
- func PrivateKeyToString(privateKey *rsa.PrivateKey) (string, error)
- func PublicKeyB64StrToStruct(publicKeyStr string) (*rsa.PublicKey, error)
- func PublicKeyToString(publicKey *rsa.PublicKey) (string, error)
- func RSADecrypt(privateKey *rsa.PrivateKey, encryptedStr string) (string, error)
- func RSAEncrypt(publicKey *rsa.PublicKey, str string) (string, error)
- func SHA1(byt []byte) string
- func SHA1MD5Str(str string) string
- func SHA1Str(str string) string
- func SHA256(byt []byte) string
- func SHA256MD5Str(str string) string
- func SHA256Str(str string) string
- func SelectFromMetadata(md metadata.MD, key string) string
- func SetHeadersForDownstream(c *gin.Context, downstreamName string) error
- func SetMetadataForDownstreamFromHttpHeaders(ctx context.Context, c *gin.Context, downstreamName string) (context.Context, error)
- func ShortUUID() string
- func SpanID() string
- func TraceID() string
- func UUIDInLower() string
- func UUIDInUpper() string
- func ValidateHeaders(c *gin.Context) error
- func ValidateMetadata(md metadata.MD) error
- func VerifyEncodedPwd(pwdHeldRaw string, salt string, pwdTarget string) bool
- type App
- type Code
- type Config
- type Consul
- type CustomClaims
- type DB
- type Downstream
- type ETCD
- type Enabled
- type Endpoint
- type Error
- type Gin
- type GormLogger
- func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})
- func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})
- func (l *GormLogger) LogMode(lev logger.LogLevel) logger.Interface
- func (l *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})
- type ILogger
- type IResponse
- type IRocketMQ
- type Jaeger
- type Jwt
- type Lib
- type Log
- type Logger
- func (l *Logger) Fail(code Code, desc string, err error)
- func (l *Logger) FailWithField(c *gin.Context, code Code, desc string, err error)
- func (l *Logger) FailWithFieldForRPC(ctx context.Context, code Code, desc string, err error)
- func (l *Logger) Succeed(desc string)
- func (l *Logger) SucceedWithField(c *gin.Context, desc string)
- func (l *Logger) SucceedWithFieldForRPC(ctx context.Context, desc string)
- type Mb
- type Mountebank
- type Redis
- type Response
- func (res *Response) ResFailure(c *gin.Context, statusCode int, code Code, desc string, err error)
- func (res *Response) ResFailureForRPC(ctx context.Context, code Code, desc string, err error)
- func (res *Response) ResJson(c *gin.Context, statusCode int, sth any)
- func (res *Response) ResSuccess(c *gin.Context, sth any)
- func (res *Response) ResSuccessForRPC(ctx context.Context)
- type RocketMQ
- type Rocketmq
- type Server
- type Trans
- type Vault
- type WhiteList
Constants ¶
View Source
const ( KV = "kv" PWD = "pwd" RSA = "rsa" JWT = "jwt" SECRET = "secret" SALT = "salt" PUK = "puk" PRK = "prk" ID = "id" APP = "app" )
vault
View Source
const ( EmptyString = "" Bearer = "Bearer " UserID = "userID" // headers params Method = "method" URI = "uri" ClientIp = "client_ip" UserAgent = "user-agent" TraceId = "trace_id" SpanId = "span_id" ParentId = "parent_id" Authorization = "authorization" AppId = "app_id" RequestId = "request_id" UserId = "user_id" RequestURI = "request_uri" Signature = "signature" // redis Nonce = "nonce" // jaeger UberTraceId = "uber-trace-id" )
View Source
const ( TokenExpired = "Token已过期" TokenNotValidYet = "Token不再有效" TokenMalformed = "Token非法" TokenInvalid = "Token无效" )
View Source
const ( Username = "liuzhao" Password = "123456" )
vault access
View Source
const FAILURE = "失败"
View Source
const SUCCESS = "成功"
logger
Variables ¶
View Source
var LoggerSet = wire.NewSet(wire.Struct(new(Logger), "*"), wire.Bind(new(ILogger), new(*Logger)))
View Source
var ResponseSet = wire.NewSet(wire.Struct(new(Response), "*"), wire.Bind(new(IResponse), new(*Response)))
Functions ¶
func BASE64Decode ¶
func BASE64DecodeStr ¶
func BASE64Encode ¶
func BASE64EncodeStr ¶
func FormatCaller ¶
func FormatInfo ¶
func GenAppSignature ¶
func GenRSAKeyPair ¶
func GetCallerFileAndLine ¶
func GetCallerName ¶
func GetClientIP ¶
func GetEncodedPwd ¶
func GetFuncName ¶
func GetFuncName() string
func GetPrivateKey ¶
func GetPrivateKey() *rsa.PrivateKey
func GetProjectPath ¶
func GetProjectPath() string
func GetPublicKey ¶
func GetPublicKeyStr ¶
func GetPublicKeyStr() string
func GetPwdEncodingOpts ¶
func GetPwdEncodingOpts() *password.Options
func GetRandomIdlePort ¶
func GetRandomIdlePort() string
func GetUserAgent ¶
func HmacSHA256 ¶
func HmacSHA256Str ¶
func InitPrometheusRegistry ¶
func InitPrometheusRegistry() *prometheus.Registry
func InitTracer ¶
func InitTracer() *jConfig.Configuration
func LogFailure ¶
func LogSuccess ¶
func LogSuccess(desc string)
func LoggerForRPC ¶
func LoggerForRPC(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
RPC 日志中间件
func PrivateKeyB64StrToStruct ¶
func PrivateKeyB64StrToStruct(privateKeyStr string) (*rsa.PrivateKey, error)
func PrivateKeyToString ¶
func PrivateKeyToString(privateKey *rsa.PrivateKey) (string, error)
func PublicKeyB64StrToStruct ¶
func RSADecrypt ¶
func RSADecrypt(privateKey *rsa.PrivateKey, encryptedStr string) (string, error)
func SHA1MD5Str ¶
func SHA256MD5Str ¶
func SetHeadersForDownstream ¶
func UUIDInLower ¶
func UUIDInLower() string
func UUIDInUpper ¶
func UUIDInUpper() string
func ValidateHeaders ¶
func ValidateMetadata ¶
Types ¶
type App ¶
type App struct { Id string Secret string Name string `mapstructure:"name"` Version string `mapstructure:"version"` Domain string `mapstructure:"domain"` PublicKey *rsa.PublicKey PrivateKey *rsa.PrivateKey PublicKeyStr string PrivateKeyStr string Salt string JWTSecret string Logger *logrus.Logger Enabled Enabled `mapstructure:"enabled"` WhiteList []WhiteList `mapstructure:"white_list"` }
type Code ¶
type Code uint32
const ( OK Code = 0 Unknown Code = 1 ConfigError Code = 2 ConnectionFailed Code = 3 ParseIssue Code = 4 MissingParameters Code = 400 Forbidden Code = 403 NotFound Code = 404 InternalServerError Code = 500 DownstreamDown Code = 5 IOException Code = 6 PermissionDenied Code = 7 DBDenied Code = 8 CacheDenied Code = 9 VaultDenied Code = 10 )
type Config ¶
type Config struct { App Lib Server Downstreams []Downstream }
func (*Config) ConvertRSAKeys ¶
func (cfg *Config) ConvertRSAKeys()
func (*Config) GetSecret ¶
func (cfg *Config) GetSecret()
GetSecret 使用client token访问vault,获取secret,存入配置对象
func (*Config) HandleLoadedConfig ¶
func (cfg *Config) HandleLoadedConfig() func()
func (*Config) SetRSAKeys ¶
func (cfg *Config) SetRSAKeys()
type Consul ¶
type CustomClaims ¶
type DB ¶
type DB struct { Type string `mapstructure:"type"` Debug bool `mapstructure:"debug"` MaxLifeTime int `mapstructure:"max_life_time"` MaxOpenConns int `mapstructure:"max_open_conns"` MaxIdleConns int `mapstructure:"max_idle_conns"` Name string `mapstructure:"name"` Params string `mapstructure:"params"` Username string `mapstructure:"username"` Password string `mapstructure:"password"` Endpoint }
type Downstream ¶
type GormLogger ¶
func InitGormLogger ¶
func InitGormLogger() *GormLogger
func (*GormLogger) Error ¶
func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})
func (*GormLogger) Info ¶
func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})
type ILogger ¶
type ILogger interface { Succeed(string) Fail(Code, string, error) SucceedWithField(*gin.Context, string) FailWithField(*gin.Context, Code, string, error) SucceedWithFieldForRPC(context.Context, string) FailWithFieldForRPC(context.Context, Code, string, error) }
ILogger 主要用于中间件和handler
type Mountebank ¶
func (*Mountebank) CreateImposter ¶
func (m *Mountebank) CreateImposter(stubDir string)
func (*Mountebank) DeleteImposter ¶
func (m *Mountebank) DeleteImposter(stubDir string)
type Response ¶
type Response struct {
Logger ILogger
}
func (*Response) ResFailure ¶
func (*Response) ResFailureForRPC ¶
func (*Response) ResSuccessForRPC ¶
type RocketMQ ¶
type RocketMQ struct { }
func (*RocketMQ) GenProducer ¶
func (*RocketMQ) GenPushConsumer ¶
type Server ¶
type Server struct { Protocol string `mapstructure:"protocol"` Host string `mapstructure:"host"` Port string `mapstructure:"port"` BaseUrl string `mapstructure:"base_url"` ReadTimeout int `mapstructure:"read_timeout"` WriteTimeout int `mapstructure:"write_timeout"` IdleTimeout int `mapstructure:"idle_timeout"` ShutdownTimeout int `mapstructure:"shutdown_timeout"` }
Click to show internal directories.
Click to hide internal directories.