From c3cbe1cd927df9c94faa73d8a6417a71d18986bb Mon Sep 17 00:00:00 2001 From: lash Date: Sat, 4 Jan 2025 09:41:17 +0000 Subject: [PATCH] Add connstr to last executable --- cmd/africastalking/main.go | 24 +++++++++++++++++------- cmd/http/main.go | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index cb83a3a..e1035e9 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -8,6 +8,7 @@ import ( "os" "os/signal" "path" + "path/filepath" "strconv" "syscall" @@ -36,23 +37,32 @@ func init() { func main() { config.LoadConfig() - var dbDir string + var connStr string var resourceDir string var size uint var database string var engineDebug bool var host string var port uint - flag.StringVar(&dbDir, "dbdir", ".state", "database dir to read from") + var err error + flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") - flag.StringVar(&database, "db", "gdbm", "database to be used") + flag.StringVar(&connStr, "c", ".", "connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host") flag.UintVar(&port, "p", initializers.GetEnvUint("PORT", 7123), "http port") flag.Parse() - logg.Infof("start command", "build", build, "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size) + if connStr == "." { + connStr, err = filepath.Abs(".state/state.gdbm") + if err != nil { + fmt.Fprintf(os.Stderr, "auto connstr generate error: %v", err) + os.Exit(1) + } + } + + logg.Infof("start command", "build", build, "dbdir", connStr, "resourcedir", resourceDir, "outputsize", size) ctx := context.Background() ctx = context.WithValue(ctx, "Database", database) @@ -69,14 +79,14 @@ func main() { cfg.EngineDebug = true } - menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir) - rs, err := menuStorageService.GetResource(ctx) + menuStorageService := storage.NewMenuStorageService(resourceDir) + err = menuStorageService.SetConn(connStr) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) } - err = menuStorageService.EnsureDbDir() + rs, err := menuStorageService.GetResource(ctx) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/http/main.go b/cmd/http/main.go index dec4e64..070cf79 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -47,6 +47,7 @@ func main() { var err error flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") + flag.StringVar(&connStr, "c", ".", "connection string") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") flag.StringVar(&host, "h", initializers.GetEnv("HOST", "127.0.0.1"), "http host")