@@ -7,21 +7,27 @@ import (
|
||||
"time"
|
||||
|
||||
appconfig "git.unistack.org/unistack-org/pkgdash/internal/config"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/database"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/handler"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/service/client_git"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/storage"
|
||||
_ "git.unistack.org/unistack-org/pkgdash/internal/storage/sqlite"
|
||||
"git.unistack.org/unistack-org/pkgdash/internal/worker"
|
||||
pb "git.unistack.org/unistack-org/pkgdash/proto"
|
||||
jsoncodec "go.unistack.org/micro-codec-json/v4"
|
||||
jsonpbcodec "go.unistack.org/micro-codec-jsonpb/v4"
|
||||
yamlcodec "go.unistack.org/micro-codec-yaml/v4"
|
||||
envconfig "go.unistack.org/micro-config-env/v4"
|
||||
fileconfig "go.unistack.org/micro-config-file/v4"
|
||||
vaultconfig "go.unistack.org/micro-config-vault/v4"
|
||||
zlogger "go.unistack.org/micro-logger-zerolog/v4"
|
||||
victoriameter "go.unistack.org/micro-meter-victoriametrics/v4"
|
||||
httpsrv "go.unistack.org/micro-server-http/v4"
|
||||
healthhandler "go.unistack.org/micro-server-http/v4/handler/health"
|
||||
meterhandler "go.unistack.org/micro-server-http/v4/handler/meter"
|
||||
"go.unistack.org/micro/v4"
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v4/logger"
|
||||
"go.unistack.org/micro/v4/meter"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
"go.unistack.org/micro/v4/server"
|
||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||
@@ -38,7 +44,7 @@ func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
logger.DefaultLogger = zlogger.NewLogger(zlogger.ReportCaller(), logger.WithLevel(logger.DebugLevel), logger.WithCallerSkipCount(3))
|
||||
logger.DefaultLogger = zlogger.NewLogger(zlogger.ReportCaller(), logger.WithLevel(logger.DebugLevel), logger.WithCallerSkipCount(4))
|
||||
if err := logger.DefaultLogger.Init(); err != nil {
|
||||
logger.Fatalf(ctx, "failed to init logger")
|
||||
}
|
||||
@@ -87,9 +93,17 @@ func main() {
|
||||
logger.Fatalf(ctx, "failed to validate config: %v", err)
|
||||
}
|
||||
|
||||
meter.DefaultMeter = victoriameter.NewMeter(
|
||||
meter.Path(cfg.Meter.Path),
|
||||
meter.WriteFDMetrics(true),
|
||||
meter.WriteProcessMetrics(true),
|
||||
options.Address(cfg.Meter.Addr),
|
||||
)
|
||||
|
||||
svc := micro.NewService()
|
||||
|
||||
if err := svc.Init(
|
||||
micro.Server(httpsrv.NewServer()),
|
||||
micro.Name(cfg.Server.Name),
|
||||
micro.Version(cfg.Server.Version),
|
||||
); err != nil {
|
||||
@@ -100,13 +114,30 @@ func main() {
|
||||
options.Address(cfg.Server.Addr),
|
||||
options.Name(cfg.Server.Name),
|
||||
server.Version(cfg.Server.Version),
|
||||
options.Codecs("application/json", jsonpbcodec.NewCodec()),
|
||||
options.Address(cfg.Server.Addr),
|
||||
options.Context(ctx),
|
||||
); err != nil {
|
||||
logger.Fatalf(ctx, "failed to init service: %v", err)
|
||||
}
|
||||
|
||||
h := handler.NewHandler(svc, client_git.NewClient(5))
|
||||
if err := h.Init(svc.Options().Context); err != nil {
|
||||
logger.Fatalf(ctx, "failed to init handler: %v", err)
|
||||
if err := database.ParseDSN(cfg.Database); err != nil {
|
||||
logger.Fatalf(ctx, "failed to init database: %v", err)
|
||||
}
|
||||
|
||||
db, err := database.Connect(ctx, cfg.Database, logger.DefaultLogger)
|
||||
if err != nil {
|
||||
logger.Fatalf(ctx, "failed to connect database: %v", err)
|
||||
}
|
||||
|
||||
store, err := storage.NewStorage(cfg.Database.Type, db)
|
||||
if err != nil {
|
||||
logger.Fatalf(ctx, "failed to init storage: %v", err)
|
||||
}
|
||||
|
||||
h, err := handler.NewHandler(store)
|
||||
if err != nil {
|
||||
logger.Fatalf(ctx, "failed to create handler: %v", err)
|
||||
}
|
||||
|
||||
log := logger.NewLogger(
|
||||
@@ -179,4 +210,12 @@ func main() {
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
worker.Run(ctx, store, time.Duration(cfg.App.CheckInterval))
|
||||
}()
|
||||
|
||||
if err = svc.Run(); err != nil {
|
||||
logger.Fatalf(ctx, "failed to run svc: %v", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user