This commit is contained in:
Rogee
2024-08-30 12:38:03 +08:00
parent 1fde6ee1ff
commit e43fa0f078
26 changed files with 647 additions and 2 deletions

46
internal/common.go Normal file
View File

@@ -0,0 +1,46 @@
package internal
import (
"context"
"exporter/config"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
lj "gopkg.in/natefinch/lumberjack.v2"
)
var (
client *TClient
logger *zap.Logger
)
func InitClient(cfg *config.Config) error {
logWriter := zapcore.AddSync(&lj.Logger{
Filename: cfg.LogFile,
MaxBackups: 3,
MaxSize: 1, // megabytes
MaxAge: 7, // days
})
logCore := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
logWriter,
zap.DebugLevel,
)
logger = zap.New(logCore)
client = NewClient(cfg)
return nil
}
func Close() error {
_ = logger.Sync()
return nil
}
func wrapE(f func(context.Context) error) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
return client.Client.Run(context.Background(), f)
}
}