2024-12-18 18:54:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"log"
|
|
|
|
|
"net"
|
2024-12-24 18:11:25 +00:00
|
|
|
"os"
|
2025-01-07 13:01:14 +00:00
|
|
|
"queryorchestration/api/controllers"
|
|
|
|
|
serviceinterfaces "queryorchestration/api/serviceInterfaces"
|
2024-12-24 17:13:48 +00:00
|
|
|
"queryorchestration/internal/collector"
|
|
|
|
|
"queryorchestration/internal/database"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
"queryorchestration/internal/export"
|
|
|
|
|
"queryorchestration/internal/otel"
|
|
|
|
|
"queryorchestration/internal/query"
|
2024-12-18 18:54:48 +00:00
|
|
|
"strconv"
|
|
|
|
|
|
2024-12-23 16:49:53 +00:00
|
|
|
"github.com/go-playground/validator/v10"
|
2024-12-18 18:54:48 +00:00
|
|
|
_ "github.com/lib/pq"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
closeTracer := otel.Init(ctx)
|
|
|
|
|
defer closeTracer()
|
|
|
|
|
|
2024-12-24 18:11:25 +00:00
|
|
|
database.RunMigrations(os.Getenv("PWD"))
|
2024-12-18 18:54:48 +00:00
|
|
|
|
|
|
|
|
host := "0.0.0.0"
|
|
|
|
|
port := 8080
|
|
|
|
|
address := net.JoinHostPort(host, strconv.Itoa(port))
|
|
|
|
|
|
|
|
|
|
lis, err := net.Listen("tcp", address)
|
|
|
|
|
if err != nil {
|
2024-12-24 18:11:25 +00:00
|
|
|
log.Panicf("failed to listen: %v", err)
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pool := database.GetDBPool(ctx)
|
|
|
|
|
db := repository.New(pool)
|
2024-12-23 16:49:53 +00:00
|
|
|
valid := validator.New()
|
2024-12-18 18:54:48 +00:00
|
|
|
|
|
|
|
|
grpcServer := grpc.NewServer()
|
2025-01-07 13:01:14 +00:00
|
|
|
serviceinterfaces.RegisterQueryServiceServer(grpcServer, controllers.NewQueryController(*query.New(db), valid))
|
|
|
|
|
serviceinterfaces.RegisterExportServiceServer(grpcServer, controllers.NewExportController(*export.New(db), valid))
|
|
|
|
|
serviceinterfaces.RegisterJobCollectorServiceServer(grpcServer, controllers.NewJobCollectorController(*collector.New(db), valid))
|
2024-12-18 18:54:48 +00:00
|
|
|
|
|
|
|
|
log.Printf("Listening on port %d", port)
|
|
|
|
|
if err := grpcServer.Serve(lis); err != nil {
|
2024-12-24 18:11:25 +00:00
|
|
|
log.Panicf("Failed to serve: %v", err)
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
}
|