infra

package
v0.0.0-...-62da268 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

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 GlobalLog

func GlobalLog() *zap.Logger

func GlobalMySQL

func GlobalMySQL() *gorm.DB

func GlobalRedis

func GlobalRedis() redis.UniversalClient

func InitGopprof

func InitGopprof(
	addr string,
) error

func InitLog

func InitLog(logPath, errPath string, logLevel zapcore.Level) *zap.Logger

初始化日志 logger

func InitMetric

func InitMetric(
	promListenAddr string,
)

Dep: Log

func InitMySQL

func InitMySQL(
	conf mysql.Config,
	gormConf gorm.Config,
	migrateFunc func(db *gorm.DB) error,
) (err error)

func InitRedis

func InitRedis(ctx context.Context, conf *redis.UniversalOptions) error

func InteragationTest

func InteragationTest(t *testing.T)

func LoadMySQLConfFromEnv

func LoadMySQLConfFromEnv(debug bool) mysql.Config

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 NewRateLimiter(
	QpsLimit uint64,
	Dur time.Duration,
) connect.UnaryInterceptorFunc

func NewRedisRpcCounter

func NewRedisRpcCounter() connect.UnaryInterceptorFunc

func NewReqRespLogger

func NewReqRespLogger() connect.UnaryInterceptorFunc

func ParseToken

func ParseToken(tokenString string) (*jwt.Token, error)

func PrepareLog

func PrepareLog(t *testing.T)

func PrintRpcCounter

func PrintRpcCounter(ctx context.Context, interval time.Duration, topk uint)

func RecoverFn

func RecoverFn(
	ctx context.Context,
	spec connect.Spec,
	header http.Header,
	recoverValue any,
) error

func SecretStrMask

func SecretStrMask(original string, tailSize int) string

Maske secret or sensitive data. "ABCDEF", 2 -> "****EF"

func SignJWT

func SignJWT(payloadMap map[string]interface{}) (string, error)

Types

type HttpResult

type HttpResult[T any] struct {
	mo.Result[T]
	// contains filtered or unexported fields
}

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 RedisConfig struct {
	HostPort string
	Pwd      string

	// 0-15, default 0
	DB uint
}

type ServerConfig

type ServerConfig struct {
	ServiceId         string
	ServiceVersion    string
	ServiceOpenapiDoc string
	DeployEnv         string
}

func (*ServerConfig) LoadFromEnv

func (sc *ServerConfig) LoadFromEnv() error

type Service

type Service struct {
	Handler        http.Handler
	Path           string
	BindingAddress string
}

func (*Service) Run

func (s *Service) Run(
	ctx context.Context,
	shutdownDur time.Duration,
)

func (*Service) RunAfterInit

func (s *Service) RunAfterInit(
	ctx context.Context,
	shutdownDur time.Duration,
	initFnList ...func() error,
)

Directories

Path Synopsis
Some useful logical operation for data processing
Some useful logical operation for data processing

Jump to

Keyboard shortcuts

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