init new statistic route

This commit is contained in:
Pavel 2024-03-25 12:47:18 +03:00
parent 92f64fa246
commit a441303acb
2 changed files with 29 additions and 26 deletions

@ -8,8 +8,13 @@ import (
"github.com/skeris/appInit"
"github.com/themakers/hlog"
"go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/backend/penahub_common/privilege"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/healthchecks"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/service"
)
@ -44,13 +49,13 @@ type Options struct {
NumberPort string `env:"PORT" default:"1488"`
CrtFile string `env:"CRT" default:"server.crt"`
KeyFile string `env:"KEY" default:"server.key"`
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
//HubAdminUrl string `env:"HUB_ADMIN_URL"`
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
//AuthServiceURL string `env:"AUTH_URL"`
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
//PubKey string `env:"PUBLIC_KEY"`
//PrivKey string `env:"PRIVATE_KEY"`
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
HubAdminUrl string `env:"HUB_ADMIN_URL"`
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
AuthServiceURL string `env:"AUTH_URL"`
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
PubKey string `env:"PUBLIC_KEY"`
PrivKey string `env:"PRIVATE_KEY"`
}
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
@ -87,9 +92,9 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
logger := hlog.New(zapLogger)
logger.Emit(InfoSvcStarted{})
//authClient := auth.NewAuthClient(options.AuthServiceURL)
authClient := auth.NewAuthClient(options.AuthServiceURL)
pgdal, err := dal.New(ctx, options.PostgresCredentials, nil)
pgdal, err := dal.New(ctx, options.PostgresCredentials, authClient)
if err != nil {
fmt.Println("NEW", err)
return nil, err
@ -100,28 +105,28 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
return nil, err
}
//clientData := privilege.Client{
// URL: options.HubAdminUrl,
// ServiceName: options.ServiceName,
// Privileges: model.Privileges,
//}
//fiberClient := &fiber.Client{}
//privilegeController := privilege.NewPrivilege(clientData, fiberClient)
//err = privilegeController.PublishPrivileges()
//if err != nil {
// fmt.Println("Failed to publish privileges", err)
//}
//
//encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
clientData := privilege.Client{
URL: options.HubAdminUrl,
ServiceName: options.ServiceName,
Privileges: model.Privileges,
}
fiberClient := &fiber.Client{}
privilegeController := privilege.NewPrivilege(clientData, fiberClient)
err = privilegeController.PublishPrivileges()
if err != nil {
fmt.Println("Failed to publish privileges", err)
}
encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
app := fiber.New()
//app.Use(middleware.JWTAuth())
app.Use(middleware.JWTAuth())
app.Get("/liveness", healthchecks.Liveness)
app.Get("/readiness", healthchecks.Readiness(&workerErr)) //todo parametrized readiness. should discuss ready reason
svc := service.New(service.Deps{
Dal: pgdal,
RedirectURl: options.RedirectURL,
Encrypt: nil,
Encrypt: encrypt,
})
svc.Register(app)

2
go.sum

@ -186,8 +186,6 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d h1:gbaDt35HMDqOK84WYmDIlXMI7rstUcRqNttaT6Kx1do=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5 h1:c9/hwlNC5nd/6M61ULCWg9BQl5wWeK21oQIaEEEGe8c=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240325084116-830f54870853 h1:wr7r6meuCAunxE/KCg93hM4XDzpII96pya4RYrwxHmc=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240325084116-830f54870853/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3 h1:BLHIUnJAttW9OAW7A63H9ON/HPhXdpBa/YPUQWD4ORA=