Phase 2/4 done, working on phase 3/5
This commit is contained in:
+33
-2
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
@@ -10,11 +11,18 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/uopi/uopi/internal/broker"
|
||||
"github.com/uopi/uopi/internal/config"
|
||||
"github.com/uopi/uopi/internal/datasource/epics"
|
||||
"github.com/uopi/uopi/internal/datasource/stub"
|
||||
"github.com/uopi/uopi/internal/server"
|
||||
"github.com/uopi/uopi/web"
|
||||
)
|
||||
|
||||
// The web package's embed.go embeds web/dist at build time.
|
||||
// This blank import ensures the compiler includes the package.
|
||||
var _ embed.FS
|
||||
|
||||
func main() {
|
||||
configPath := flag.String("config", "", "path to TOML config file (optional)")
|
||||
flag.Parse()
|
||||
@@ -38,11 +46,34 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
srv := server.New(cfg.Server.Listen, webFS, log)
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
brk := broker.New(ctx, log)
|
||||
|
||||
// Register data sources
|
||||
if cfg.Synthetic.Enabled {
|
||||
ds := stub.New()
|
||||
if err := ds.Connect(ctx); err != nil {
|
||||
log.Error("stub connect", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
brk.Register(ds)
|
||||
}
|
||||
// Register EPICS Channel Access data source (Phase 2).
|
||||
// epics.Available() returns false when built without -tags epics so that
|
||||
// machines without EPICS Base installed still compile and run correctly.
|
||||
if cfg.EPICS.Enabled && epics.Available() {
|
||||
ds := epics.New(cfg.EPICS.CAAddrList, cfg.EPICS.ArchiveURL)
|
||||
if err := ds.Connect(ctx); err != nil {
|
||||
log.Error("epics connect", "err", err)
|
||||
} else {
|
||||
brk.Register(ds)
|
||||
}
|
||||
}
|
||||
|
||||
srv := server.New(cfg.Server.Listen, webFS, brk, log)
|
||||
|
||||
if err := srv.Start(ctx); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "server error: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user