Reinstate http server configs, rehabilitate cmd cli
This commit is contained in:
parent
f089822300
commit
b194dc7c59
@ -6,7 +6,7 @@ HOST=127.0.0.1
|
|||||||
AT_ENDPOINT=/ussd/africastalking
|
AT_ENDPOINT=/ussd/africastalking
|
||||||
|
|
||||||
#PostgreSQL
|
#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_TIMEZONE=Africa/Nairobi
|
||||||
#DB_SCHEMA=vise
|
#DB_SCHEMA=vise
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ func main() {
|
|||||||
var connStr string
|
var connStr string
|
||||||
var resourceDir string
|
var resourceDir string
|
||||||
var size uint
|
var size uint
|
||||||
var database string
|
|
||||||
var engineDebug bool
|
var engineDebug bool
|
||||||
var host string
|
var host string
|
||||||
var port uint
|
var port uint
|
||||||
@ -71,7 +70,6 @@ func main() {
|
|||||||
logg.Infof("start command", "build", build, "conn", connData, "resourcedir", resourceDir, "outputsize", size)
|
logg.Infof("start command", "build", build, "conn", connData, "resourcedir", resourceDir, "outputsize", size)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = context.WithValue(ctx, "Database", database)
|
|
||||||
ln, err := lang.LanguageFromCode(config.Language())
|
ln, err := lang.LanguageFromCode(config.Language())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "default language set error: %v", err)
|
fmt.Fprintf(os.Stderr, "default language set error: %v", err)
|
||||||
|
23
cmd/main.go
23
cmd/main.go
@ -47,12 +47,12 @@ func main() {
|
|||||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if connStr != "" {
|
if connStr == "" {
|
||||||
connStr = config.DbConn()
|
connStr = config.DbConn()
|
||||||
}
|
}
|
||||||
connData, err := storage.ToConnData(connStr)
|
connData, err := storage.ToConnData(connStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
fmt.Fprintf(os.Stderr, "connstr err: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ func main() {
|
|||||||
|
|
||||||
ln, err := lang.LanguageFromCode(config.Language())
|
ln, err := lang.LanguageFromCode(config.Language())
|
||||||
if err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, "Language", ln)
|
ctx = context.WithValue(ctx, "Language", ln)
|
||||||
@ -82,9 +82,9 @@ func main() {
|
|||||||
MenuSeparator: menuSeparator,
|
MenuSeparator: menuSeparator,
|
||||||
}
|
}
|
||||||
|
|
||||||
menuStorageService := storage.NewMenuStorageService(connData, "")
|
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||||
if err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,41 +94,40 @@ func main() {
|
|||||||
|
|
||||||
rs, err := menuStorageService.GetResource(ctx)
|
rs, err := menuStorageService.GetResource(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "get resource error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pe, err := menuStorageService.GetPersister(ctx)
|
pe, err := menuStorageService.GetPersister(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "get persister error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
userdatastore, err := menuStorageService.GetUserdataDb(ctx)
|
userdatastore, err := menuStorageService.GetUserdataDb(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "get userdata db error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbResource, ok := rs.(*resource.DbResource)
|
dbResource, ok := rs.(*resource.DbResource)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "get dbresource error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||||
lhs.SetDataStore(&userdatastore)
|
lhs.SetDataStore(&userdatastore)
|
||||||
lhs.SetPersister(pe)
|
lhs.SetPersister(pe)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "localhandler service error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountService := &httpremote.HTTPAccountService{}
|
accountService := &httpremote.HTTPAccountService{}
|
||||||
hl, err := lhs.GetHandler(accountService)
|
hl, err := lhs.GetHandler(accountService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "get accounts service handler: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,8 +13,11 @@ func init() {
|
|||||||
const (
|
const (
|
||||||
defaultSSHHost string = "127.0.0.1"
|
defaultSSHHost string = "127.0.0.1"
|
||||||
defaultSSHPort uint = 7122
|
defaultSSHPort uint = 7122
|
||||||
|
defaultHTTPHost string = "127.0.0.1"
|
||||||
|
defaultHTTPPort uint = 7123
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func LoadConfig() error {
|
func LoadConfig() error {
|
||||||
err := viseconfig.LoadConfig()
|
err := viseconfig.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,11 +39,11 @@ func Language() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Host() string {
|
func Host() string {
|
||||||
return apiconfig.Host()
|
return env.GetEnv("HOST", defaultHTTPHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Port() uint {
|
func Port() uint {
|
||||||
return apiconfig.Port()
|
return env.GetEnvUint("PORT", defaultHTTPPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HostSSH() string {
|
func HostSSH() string {
|
||||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.23.4
|
|||||||
require (
|
require (
|
||||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
|
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/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 v0.8.0-beta.10.0.20250112121325-9e4c65c8b4d1
|
||||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5
|
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5
|
||||||
github.com/alecthomas/assert/v2 v2.2.2
|
github.com/alecthomas/assert/v2 v2.2.2
|
||||||
|
4
go.sum
4
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.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 h1:dQ8DtiOUPzzXYgZw6REnIc1dhb3PzCEfN01Rd7Pbw+o=
|
||||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112102149-4feac5e490e9/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
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-20250112152617-1865917cb38a h1:nXZEc2pCIZLON4TmBFFPszy7gSfcCAf4Rrgaiduvjp8=
|
||||||
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/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 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 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=
|
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 h1:byD+vsY9kqCVFX2Kx2+Z3/Lqk10l4MQnUBXm/zLpy20=
|
||||||
|
@ -75,7 +75,7 @@ func GetVoucherData(ctx context.Context, db storedb.PrefixDb, input string) (*da
|
|||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
value, err := db.Get(ctx, storedb.ToBytes(key))
|
value, err := db.Get(ctx, storedb.ToBytes(key))
|
||||||
if err != nil {
|
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)
|
data[key] = string(value)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user