Documentation ¶
Index ¶
- Constants
- Variables
- func GlobalLog() *zap.Logger
- func GlobalMySQL() *gorm.DB
- func GlobalRedis() redis.UniversalClient
- func InitGopprof(addr string) error
- func InitLog(logPath, errPath string, logLevel zapcore.Level) *zap.Logger
- func InitMetric(promListenAddr string)
- func InitMySQL(conf mysql.Config, gormConf gorm.Config, migrateFunc func(db *gorm.DB) error) (err error)
- func InitRedis(ctx context.Context, conf *redis.UniversalOptions) error
- func InteragationTest(t *testing.T)
- func LoadMySQLConfFromEnv(debug bool) mysql.Config
- func LoadRedisConfigFromEnv() *redis.UniversalOptions
- func MiddlewareJWTAuth(svcJwtSecret string) connect.UnaryInterceptorFunc
- func NewLocalRpcCounter() connect.UnaryInterceptorFunc
- func NewRateLimiter(QpsLimit uint64, Dur time.Duration) connect.UnaryInterceptorFunc
- func NewRedisRpcCounter() connect.UnaryInterceptorFunc
- func NewReqRespLogger() connect.UnaryInterceptorFunc
- func ParseToken(tokenString string) (*jwt.Token, error)
- func PrepareLog(t *testing.T)
- func PrintRpcCounter(ctx context.Context, interval time.Duration, topk uint)
- func RecoverFn(ctx context.Context, spec connect.Spec, header http.Header, recoverValue any) error
- func SecretStrMask(original string, tailSize int) string
- func SignJWT(payloadMap map[string]interface{}) (string, error)
- type HttpResult
- type RedisConfig
- type ServerConfig
- type Service
Constants ¶
View Source
const ( ENV_LIVE = "live" ENV_TEST = "test" ENV_DEV = "dev" )
Variables ¶
View Source
var ( CODE_SUCCESS = 0 CODE_INTERNAL = 500 CODE_EXTERNAL = 1000 )
View Source
var ( MSG_SUCCESS = "success" MSG_INTERNAL = "internal error" MSG_EXTERNAL = "external error" )
View Source
var DEFAULT_PPROF_ADDR = ":6060"
View Source
var (
KEY_RPC_COUNTER = "rpc_counter"
)
View Source
var (
PROMETHEUS_LISTEN_ADDR = utils.StrOrDefault(os.Getenv("PROMETHEUS_LISTEN_ADDR"), ":9090")
)
View Source
var ( // key=string, valuee=uint64 RPC_COUNTER = sync.Map{} )
Functions ¶
func GlobalMySQL ¶
func GlobalRedis ¶
func GlobalRedis() redis.UniversalClient
func InitGopprof ¶
func InteragationTest ¶
func LoadMySQLConfFromEnv ¶
func LoadRedisConfigFromEnv ¶
func LoadRedisConfigFromEnv() *redis.UniversalOptions
func MiddlewareJWTAuth ¶
func MiddlewareJWTAuth( svcJwtSecret string, ) connect.UnaryInterceptorFunc
Panic if svcJwtSecret is invalid.
func NewLocalRpcCounter ¶
func NewLocalRpcCounter() connect.UnaryInterceptorFunc
func NewRateLimiter ¶
func NewRedisRpcCounter ¶
func NewRedisRpcCounter() connect.UnaryInterceptorFunc
func NewReqRespLogger ¶
func NewReqRespLogger() connect.UnaryInterceptorFunc
func PrepareLog ¶
func SecretStrMask ¶
Maske secret or sensitive data. "ABCDEF", 2 -> "****EF"
Types ¶
type HttpResult ¶
func InvokeExternalAPI ¶
func InvokeExternalAPI[T any]() *HttpResult[T]
Record req, resp and raw http body for reasoning.
func (*HttpResult[T]) IsNetworkErr ¶
func (r *HttpResult[T]) IsNetworkErr() bool
type RedisConfig ¶
type ServerConfig ¶
type ServerConfig struct { ServiceId string ServiceVersion string ServiceOpenapiDoc string DeployEnv string }
func (*ServerConfig) LoadFromEnv ¶
func (sc *ServerConfig) LoadFromEnv() error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.