sarafu-vise-events/cmd/main.go

64 lines
1.4 KiB
Go
Raw Normal View History

2024-10-23 22:01:10 +02:00
package main
import (
"context"
"flag"
2024-10-23 22:01:10 +02:00
"fmt"
"os"
"os/signal"
"syscall"
2025-01-13 09:28:29 +01:00
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/config"
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/event/nats"
2025-01-13 18:47:21 +01:00
"git.grassecon.net/grassrootseconomics/sarafu-vise-events/lookup"
viseevent "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
2024-10-23 22:01:10 +02:00
)
2025-01-13 09:28:29 +01:00
var (
logg = logging.NewVanilla()
)
2024-10-23 22:01:10 +02:00
func main() {
config.LoadConfig()
var connStr string
2024-12-05 16:17:36 +01:00
flag.StringVar(&connStr, "c", "", "connection string")
flag.Parse()
2025-01-13 09:15:45 +01:00
if connStr == "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
os.Exit(1)
}
2025-01-13 09:28:29 +01:00
logg.Infof("start command", "conn", connData)
ctx := context.Background()
menuStorageService := storage.NewMenuStorageService(connData, "")
2025-01-13 18:47:21 +01:00
eh := viseevent.NewEventsHandler(lookup.Api)
n := nats.NewNatsSubscription(menuStorageService, eh)
err = n.Connect(ctx, config.JetstreamURL)
2024-10-23 22:01:10 +02:00
if err != nil {
fmt.Fprintf(os.Stderr, "Stream connect err: %v", err)
2024-10-23 22:01:10 +02:00
os.Exit(1)
}
defer n.Close()
cint := make(chan os.Signal)
cterm := make(chan os.Signal)
signal.Notify(cint, os.Interrupt, syscall.SIGINT)
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
select {
case _ = <-cint:
case _ = <-cterm:
}
}