Reinstate http server configs, rehabilitate cmd cli

This commit is contained in:
lash 2025-01-12 15:29:12 +00:00
parent f089822300
commit b194dc7c59
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 21 additions and 21 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)
}

View File

@ -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 {

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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)
}