diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index e23e3e9..2fd76de 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -17,7 +17,6 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/session" @@ -35,10 +34,6 @@ var ( menuSeparator = ": " ) -func init() { - env.LoadEnvVariables() -} - func main() { config.LoadConfig() @@ -58,8 +53,8 @@ func main() { 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", env.GetEnv("HOST", "127.0.0.1"), "http host") - flag.UintVar(&port, "p", env.GetEnvUint("PORT", 7123), "http port") + flag.StringVar(&host, "h", config.Host(), "http host") + flag.UintVar(&port, "p", config.Port(), "http port") flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory") flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() @@ -147,7 +142,7 @@ func main() { sh := at.NewATRequestHandler(bsh) mux := http.NewServeMux() - mux.Handle(env.GetEnv("AT_ENDPOINT", "/"), sh) + mux.Handle(config.ATEndpoint(), sh) s := &http.Server{ Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))), diff --git a/cmd/async/main.go b/cmd/async/main.go index 3f76da5..891bd33 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -15,7 +15,6 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/session" "git.grassecon.net/grassrootseconomics/visedriver/request" @@ -30,10 +29,6 @@ var ( menuSeparator = ": " ) -func init() { - env.LoadEnvVariables() -} - type asyncRequestParser struct { sessionId string input []byte @@ -66,8 +61,8 @@ func main() { 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", env.GetEnv("HOST", "127.0.0.1"), "http host") - flag.UintVar(&port, "p", env.GetEnvUint("PORT", 7123), "http port") + flag.StringVar(&host, "h", config.Host(), "http host") + flag.UintVar(&port, "p", config.Port(), "http port") flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory") flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() diff --git a/cmd/http/main.go b/cmd/http/main.go index becb376..eb091ba 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -17,7 +17,6 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" httpsession "git.grassecon.net/grassrootseconomics/visedriver/session/http" "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/session" @@ -33,10 +32,6 @@ var ( menuSeparator = ": " ) -func init() { - env.LoadEnvVariables() -} - func main() { config.LoadConfig() @@ -54,8 +49,8 @@ func main() { 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", env.GetEnv("HOST", "127.0.0.1"), "http host") - flag.UintVar(&port, "p", env.GetEnvUint("PORT", 7123), "http port") + flag.StringVar(&host, "h", config.Host(), "http host") + flag.UintVar(&port, "p", config.Port(), "http port") flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory") flag.Var(&langs, "language", "add symbol resolution for language") flag.Parse() diff --git a/cmd/main.go b/cmd/main.go index d6fa3f3..240cb8d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -12,7 +12,6 @@ import ( "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/lang" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/visedriver/storage" httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" "git.grassecon.net/grassrootseconomics/sarafu-vise/args" @@ -25,9 +24,6 @@ var ( menuSeparator = ": " ) -func init() { - env.LoadEnvVariables() -} // TODO: external script automatically generate language handler list from select language vise code OR consider dynamic menu generation script possibility func main() { diff --git a/cmd/ssh/main.go b/cmd/ssh/main.go index 8498fb4..03fa024 100644 --- a/cmd/ssh/main.go +++ b/cmd/ssh/main.go @@ -15,7 +15,6 @@ import ( "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/sarafu-vise/ssh" "git.grassecon.net/grassrootseconomics/visedriver/storage" ) @@ -29,10 +28,6 @@ var ( build = "dev" ) -func init() { - env.LoadEnvVariables() -} - func main() { config.LoadConfig() @@ -49,8 +44,8 @@ func main() { flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir") flag.BoolVar(&engineDebug, "d", false, "use engine debug output") flag.UintVar(&size, "s", 160, "max size of output") - flag.StringVar(&host, "h", "127.0.0.1", "socket host") - flag.UintVar(&port, "p", 7122, "socket port") + flag.StringVar(&host, "h", config.HostSSH(), "socket host") + flag.UintVar(&port, "p", config.PortSSH(), "socket port") flag.Parse() if connStr == "" { diff --git a/config/config.go b/config/config.go index 1a2032b..03f8e24 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,20 @@ package config import ( + "git.grassecon.net/grassrootseconomics/visedriver/env" viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config" apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config" ) +func init() { + env.LoadEnvVariables() +} + +const ( + defaultSSHHost string = "127.0.0.1" + defaultSSHPort uint = 7122 +) + var ( DbConn = viseconfig.DbConn DefaultLanguage = viseconfig.DefaultLanguage @@ -23,3 +33,23 @@ func LoadConfig() error { DefaultLanguage = viseconfig.DefaultLanguage return nil } + +func Host() string { + return apiconfig.Host() +} + +func Port() uint { + return apiconfig.Port() +} + +func HostSSH() string { + return defaultSSHHost +} + +func PortSSH() uint { + return defaultSSHPort +} + +func ATEndpoint() string { + return env.GetEnv("AT_ENDPOINT", "/") +} diff --git a/devtools/lang/main.go b/devtools/lang/main.go index a9af774..6023927 100644 --- a/devtools/lang/main.go +++ b/devtools/lang/main.go @@ -11,7 +11,6 @@ import ( "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/lang" "git.grassecon.net/grassrootseconomics/visedriver/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" ) const ( @@ -35,10 +34,6 @@ var ( incmps string ) -func init() { - env.LoadEnvVariables() -} - func toLanguageLabel(ln lang.Language) string { s := ln.Name v := strings.Split(s, " (") diff --git a/devtools/store/dump/main.go b/devtools/store/dump/main.go index af9891d..ee66e21 100644 --- a/devtools/store/dump/main.go +++ b/devtools/store/dump/main.go @@ -8,7 +8,6 @@ import ( "path" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/sarafu-vise/debug" "git.defalsify.org/vise.git/db" @@ -20,11 +19,6 @@ var ( scriptDir = path.Join("services", "registration") ) -func init() { - env.LoadEnvVariables() -} - - func formatItem(k []byte, v []byte) (string, error) { o, err := debug.FromKey(k) if err != nil { diff --git a/devtools/store/generate/main.go b/devtools/store/generate/main.go index 58881e8..491beca 100644 --- a/devtools/store/generate/main.go +++ b/devtools/store/generate/main.go @@ -12,7 +12,6 @@ import ( "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/visedriver/env" "git.grassecon.net/grassrootseconomics/sarafu-vise/store" storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" ) @@ -23,10 +22,6 @@ var ( scriptDir = path.Join("services", "registration") ) -func init() { - env.LoadEnvVariables() -} - func main() { config.LoadConfig() diff --git a/go.mod b/go.mod index 1c75cc8..12c10b2 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-20250112102608-1152fb71a590 + git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112110836-26a51bc95f38 git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112104023-611c5a8dfc80 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 28d17f5..e425403 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-20250112102608-1152fb71a590 h1:2twsWy9E3aWgKeY1rNaD/CTq2VtAQfaAhOstTQVQQrc= -git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250112102608-1152fb71a590/go.mod h1:vgPJiqbRBlpsMt1iFd94onNvE7I9s6r78Ph2CpxOUMs= +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/visedriver v0.8.0-beta.10.0.20250112104023-611c5a8dfc80 h1:8j7iDSC9lzOM8NexEQlMfEn+3mJStDf66OTZK8ulsho= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250112104023-611c5a8dfc80/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250112104256-7d37d7f5cac5 h1:byD+vsY9kqCVFX2Kx2+Z3/Lqk10l4MQnUBXm/zLpy20=