cbd1d5f067
Add tests for queuing * startingtest * queuerunnertest * addedtestfuncs * testtests * passintegration * unittests
49 lines
859 B
Go
49 lines
859 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/database/repository"
|
|
"queryorchestration/internal/otel"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
type Config struct {
|
|
Database *database.Connection
|
|
Validator *validator.Validate
|
|
}
|
|
|
|
type NewConfig struct {
|
|
BasePath string
|
|
}
|
|
|
|
func New(ctx context.Context, cfg *NewConfig) *Config {
|
|
closeTracer := otel.New(ctx)
|
|
defer closeTracer()
|
|
|
|
database.RunMigrations(ctx, &database.MigrationConfig{
|
|
BasePath: cfg.BasePath,
|
|
})
|
|
|
|
valid := validator.New()
|
|
|
|
dbPool := database.GetDBPool(ctx)
|
|
dbQueries := repository.New(dbPool)
|
|
db := &database.Connection{
|
|
Pool: dbPool,
|
|
Queries: dbQueries,
|
|
}
|
|
|
|
err := dbPool.Ping(ctx)
|
|
if err != nil {
|
|
log.Panic("Unable to ping database")
|
|
}
|
|
|
|
return &Config{
|
|
Database: db,
|
|
Validator: valid,
|
|
}
|
|
}
|