2025-01-10 11:12:03 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-01-31 13:43:55 +00:00
|
|
|
"queryorchestration/internal/database/migrations"
|
2025-01-17 12:00:32 +00:00
|
|
|
"queryorchestration/internal/server/otel"
|
2025-01-31 13:43:55 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
2025-01-10 11:12:03 +00:00
|
|
|
|
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
type Config interface {
|
|
|
|
|
serviceconfig.ConfigProvider
|
|
|
|
|
SetValidator()
|
|
|
|
|
GetValidator() *validator.Validate
|
2025-01-10 11:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
type BaseConfig struct {
|
|
|
|
|
serviceconfig.BaseConfig
|
|
|
|
|
Validator *validator.Validate
|
2025-01-10 11:12:03 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
func (c *BaseConfig) SetValidator() {
|
|
|
|
|
valid := validator.New()
|
2025-01-10 11:12:03 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
c.Validator = valid
|
|
|
|
|
}
|
|
|
|
|
func (c *BaseConfig) GetValidator() *validator.Validate {
|
|
|
|
|
return c.Validator
|
|
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
func New(ctx context.Context, cfg Config) (func() error, error) {
|
|
|
|
|
closeTracer := otel.New(ctx, cfg)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
err := migrations.Run(ctx, cfg)
|
|
|
|
|
if err != nil {
|
2025-02-03 17:30:50 +00:00
|
|
|
return func() error { return nil }, err
|
2025-01-10 11:12:03 +00:00
|
|
|
}
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
cfg.SetValidator()
|
|
|
|
|
|
|
|
|
|
err = cfg.SetDBPool(ctx)
|
2025-01-10 19:17:20 +00:00
|
|
|
if err != nil {
|
2025-02-03 17:30:50 +00:00
|
|
|
return func() error { return nil }, err
|
2025-01-10 19:17:20 +00:00
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
return closeTracer, nil
|
2025-01-10 11:12:03 +00:00
|
|
|
}
|