2024-10-23 22:01:10 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-11-04 00:08:50 +01:00
|
|
|
"flag"
|
2024-10-23 22:01:10 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2024-11-03 20:04:44 +01:00
|
|
|
"git.grassecon.net/urdt/ussd/initializers"
|
2024-11-04 00:08:50 +01:00
|
|
|
"git.grassecon.net/urdt/ussd/common"
|
2024-11-03 18:43:07 +01:00
|
|
|
"git.grassecon.net/term/config"
|
2024-10-23 22:01:10 +02:00
|
|
|
"git.grassecon.net/term/event/nats"
|
|
|
|
)
|
|
|
|
|
2024-12-06 18:04:14 +01:00
|
|
|
var build = "dev"
|
|
|
|
|
2024-11-03 20:04:44 +01:00
|
|
|
func init() {
|
|
|
|
initializers.LoadEnvVariables()
|
|
|
|
}
|
|
|
|
|
2024-10-23 22:01:10 +02:00
|
|
|
func main() {
|
2024-11-04 00:08:50 +01:00
|
|
|
config.LoadConfig()
|
|
|
|
|
2024-12-05 16:17:36 +01:00
|
|
|
var database string
|
2024-11-04 00:08:50 +01:00
|
|
|
var dbDir string
|
2024-12-05 16:17:36 +01:00
|
|
|
|
|
|
|
flag.StringVar(&database, "db", "gdbm", "database to be used")
|
2024-11-04 00:08:50 +01:00
|
|
|
flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from")
|
|
|
|
flag.Parse()
|
|
|
|
|
2024-10-23 22:01:10 +02:00
|
|
|
ctx := context.Background()
|
2024-12-05 16:17:36 +01:00
|
|
|
ctx = context.WithValue(ctx, "Database", database)
|
2024-11-04 00:08:50 +01:00
|
|
|
// db := mem.NewMemDb()
|
|
|
|
// err := db.Connect(ctx, "")
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Fprintf(os.Stderr, "Db connect err: %v", err)
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
|
|
|
|
|
|
|
menuStorageService := common.NewStorageService(dbDir)
|
|
|
|
err := menuStorageService.EnsureDbDir()
|
2024-11-02 16:38:23 +01:00
|
|
|
if err != nil {
|
2024-11-04 00:08:50 +01:00
|
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
2024-11-02 16:38:23 +01:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-11-04 00:08:50 +01:00
|
|
|
|
|
|
|
n := nats.NewNatsSubscription(menuStorageService)
|
2024-11-03 18:43:07 +01:00
|
|
|
err = n.Connect(ctx, config.JetstreamURL)
|
2024-10-23 22:01:10 +02:00
|
|
|
if err != nil {
|
2024-11-02 16:38:23 +01:00
|
|
|
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:
|
|
|
|
}
|
|
|
|
}
|