Files
query-orchestration/cmd/queryAPI/main.go
T
2025-04-11 16:46:05 -07:00

127 lines
3.7 KiB
Go

// This API currently manages all user entities to be managed. This allows users of the service to change required entities and processes.
//
// The entities in question:
//
// - Client - A client is a single client of the Doczy project, all configurations and clients for a client will be in reference to the respective client.
//
// - Collector - A collector specifies the required queries for export for a given client.
//
// - Sample - A sample is a subset of documents to be used for testing. When it is active a client will only process documents in the sample.
//
// - Query - A query is a block of processing of data which takes an input and produces an output.
//
// - Export - An export is a manually started process which outputs the results for a client to a given location.
package main
import (
"context"
"fmt"
"log/slog"
"os"
queryapi "queryorchestration/api/queryAPI"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/client"
"queryorchestration/internal/collector"
collectorset "queryorchestration/internal/collector/set"
"queryorchestration/internal/document"
"queryorchestration/internal/export"
"queryorchestration/internal/query"
"queryorchestration/internal/query/result"
querytest "queryorchestration/internal/query/test"
queryupdate "queryorchestration/internal/query/update"
"queryorchestration/internal/server/api"
"queryorchestration/internal/serviceconfig/queue/clientsync"
"queryorchestration/internal/serviceconfig/queue/queryversionsync"
"github.com/getkin/kin-openapi/openapi3"
_ "github.com/lib/pq"
)
type QueryAPIConfig struct {
api.BaseConfig
clientsync.ClientSyncConfig
queryversionsync.QueryVersionSyncConfig
}
func main() {
ctx := context.Background()
cfg := &QueryAPIConfig{}
cfg.RegisterHandlersFunc = func() (*openapi3.T, error) {
exp := export.New()
que := query.New(cfg)
res := result.New(cfg, &result.Services{
Query: que,
})
col := collector.New(cfg)
colupdate := collectorset.New(cfg, &collectorset.Services{
Collector: col,
})
cli := client.New(cfg)
doc := document.New(cfg)
quetest := querytest.New(cfg, &querytest.Services{
Collector: col,
Result: res,
Document: doc,
})
qupdate := queryupdate.New(cfg, &queryupdate.Services{
Query: que,
})
services := &queryapi.Services{
Export: exp,
Collector: col,
CollectorSet: colupdate,
Query: que,
QueryUpdate: qupdate,
QueryTest: quetest,
Client: cli,
Document: doc,
}
cons := queryapi.NewControllers(services)
queryapi.RegisterHandlers(cfg.Router, cons)
swagger, err := queryapi.GetSwagger()
if err != nil {
return nil, fmt.Errorf("error loading swagger: %s", err)
}
return swagger, nil
}
// Both of these operations (InitializeConfig and InitializeAuthProvider)
// would be better off in the service.new but there are code dependencies
// that make this not possible right now without significant refactoring.
// This must be done before the rbac.InitializeAuthProvider
errInitializingConfig := serviceconfig.InitializeConfig(cfg)
if errInitializingConfig != nil {
slog.Error(errInitializingConfig.Error())
os.Exit(1)
}
// Authentication specific config.
// This may move to another function after refactoring is done.
// replace the path here with value from ENV
baseUrl := "http://localhost:8080"
errorInitializingAuthConfig := cfg.InitializeAuthConfig(baseUrl, cfg.GetLogger())
// join initErr with errorInitializingAuthConfig
if errorInitializingAuthConfig != nil {
slog.Error(errorInitializingAuthConfig.Error())
os.Exit(1)
}
server, err := api.New(ctx, cfg)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
server.Listen()
}