From b194dc7c594894221ddc5a11b73bb573d085a534 Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 12 Jan 2025 15:29:12 +0000 Subject: [PATCH] Reinstate http server configs, rehabilitate cmd cli --- .env.example | 2 +- cmd/africastalking/main.go | 2 -- cmd/main.go | 23 +++++++++++------------ config/config.go | 7 +++++-- go.mod | 2 +- go.sum | 4 ++-- store/vouchers.go | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index 6d0368f..f518d39 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,7 @@ HOST=127.0.0.1 AT_ENDPOINT=/ussd/africastalking #PostgreSQL -DB_CONN=postgres://postgres:strongpass@localhost:5432/urdt_ussd +DB_CONN=postgres://postgres:strongpass@localhost:5432/urdt_ussd?search_path=vise #DB_TIMEZONE=Africa/Nairobi #DB_SCHEMA=vise diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 3e4420c..fe33d85 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -40,7 +40,6 @@ func main() { var connStr string var resourceDir string var size uint - var database string var engineDebug bool var host string var port uint @@ -71,7 +70,6 @@ func main() { logg.Infof("start command", "build", build, "conn", connData, "resourcedir", resourceDir, "outputsize", size) ctx := context.Background() - ctx = context.WithValue(ctx, "Database", database) ln, err := lang.LanguageFromCode(config.Language()) if err != nil { fmt.Fprintf(os.Stderr, "default language set error: %v", err) diff --git a/cmd/main.go b/cmd/main.go index 493090a..723fb82 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -47,12 +47,12 @@ func main() { flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() - if connStr != "" { + if connStr == "" { connStr = config.DbConn() } connData, err := storage.ToConnData(connStr) if err != nil { - fmt.Fprintf(os.Stderr, "connstr err: %v", err) + fmt.Fprintf(os.Stderr, "connstr err: %v\n", err) os.Exit(1) } @@ -67,7 +67,7 @@ func main() { ln, err := lang.LanguageFromCode(config.Language()) if err != nil { - fmt.Fprintf(os.Stderr, "default language set error: %v", err) + fmt.Fprintf(os.Stderr, "default language set error: %v\n", err) os.Exit(1) } ctx = context.WithValue(ctx, "Language", ln) @@ -82,9 +82,9 @@ func main() { MenuSeparator: menuSeparator, } - menuStorageService := storage.NewMenuStorageService(connData, "") + menuStorageService := storage.NewMenuStorageService(connData, resourceDir) if err != nil { - fmt.Fprintf(os.Stderr, "menu storage service error: %v", err) + fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err) os.Exit(1) } @@ -94,41 +94,40 @@ func main() { rs, err := menuStorageService.GetResource(ctx) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "get resource error: %v\n", err) os.Exit(1) } pe, err := menuStorageService.GetPersister(ctx) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "get persister error: %v\n", err) os.Exit(1) } userdatastore, err := menuStorageService.GetUserdataDb(ctx) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "get userdata db error: %v\n", err) os.Exit(1) } dbResource, ok := rs.(*resource.DbResource) if !ok { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "get dbresource error: %v\n", err) os.Exit(1) } lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs) lhs.SetDataStore(&userdatastore) lhs.SetPersister(pe) - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "localhandler service error: %v\n", err) os.Exit(1) } accountService := &httpremote.HTTPAccountService{} hl, err := lhs.GetHandler(accountService) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "get accounts service handler: %v\n", err) os.Exit(1) } diff --git a/config/config.go b/config/config.go index 3df8afc..61521f2 100644 --- a/config/config.go +++ b/config/config.go @@ -13,8 +13,11 @@ func init() { const ( defaultSSHHost string = "127.0.0.1" defaultSSHPort uint = 7122 + defaultHTTPHost string = "127.0.0.1" + defaultHTTPPort uint = 7123 ) + func LoadConfig() error { err := viseconfig.LoadConfig() if err != nil { @@ -36,11 +39,11 @@ func Language() string { } func Host() string { - return apiconfig.Host() + return env.GetEnv("HOST", defaultHTTPHost) } func Port() uint { - return apiconfig.Port() + return env.GetEnvUint("PORT", defaultHTTPPort) } func HostSSH() string { diff --git a/go.mod b/go.mod index 5cedcbb..1d8cdeb 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9 - git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38 + git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112152617-1865917cb38a git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index ca35ba3..34f37ae 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSG git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9 h1:dQ8DtiOUPzzXYgZw6REnIc1dhb3PzCEfN01Rd7Pbw+o= git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= -git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38 h1:M++O6THA26LRdC7jfsPCaIIPMosNhFc+PgnEtDY3+hk= -git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38/go.mod h1:E0ayNSbqpt+aAHoA7f7jXZcH2Zgjkt7rYs50YH9sLgk= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112152617-1865917cb38a h1:nXZEc2pCIZLON4TmBFFPszy7gSfcCAf4Rrgaiduvjp8= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112152617-1865917cb38a/go.mod h1:SiWT0rbK9QhFpmpAbXOtararIKDmiaAcFLHMCqKibKg= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1 h1:RfU5/WFfPxDptlkyx4MT+4YmO79sY6HvIngUq5uwQPU= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 h1:byD+vsY9kqCVFX2Kx2+Z3/Lqk10l4MQnUBXm/zLpy20= diff --git a/store/vouchers.go b/store/vouchers.go index 37381a4..ca8a75f 100644 --- a/store/vouchers.go +++ b/store/vouchers.go @@ -75,7 +75,7 @@ func GetVoucherData(ctx context.Context, db storedb.PrefixDb, input string) (*da for _, key := range keys { value, err := db.Get(ctx, storedb.ToBytes(key)) if err != nil { - return nil, fmt.Errorf("failed to get %s: %v", storedb.ToBytes(key), err) + return nil, fmt.Errorf("failed to get prefix key %x: %v", storedb.ToBytes(key), err) } data[key] = string(value) }