diff options
| author | Jeff Carr <[email protected]> | 2025-09-13 05:33:11 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-13 05:33:11 -0500 |
| commit | 0f895e83e62749bb1d716033f5f300d9d1c548ac (patch) | |
| tree | f0d29c4b96f998469cefe140006c4e0a20a361aa /init.go | |
| parent | ce4af38e8b7f05a6d8b48bc957091de0b0b0a9e7 (diff) | |
use config GO library
Diffstat (limited to 'init.go')
| -rw-r--r-- | init.go | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -4,6 +4,7 @@ package forgepb import ( "os" + "path/filepath" "go.wit.com/lib/config" "go.wit.com/lib/fhelp" @@ -12,13 +13,14 @@ import ( ) /* better syntax from gin + Default returns an Engine instance with the Logger and Recovery middleware already attached. func Default(opts ...OptionFunc) *Engine { - debugPrintWARNINGDefault() engine := New() engine.Use(Logger(), Recovery()) return engine.With(opts...) } + */ func Init() *Forge { @@ -58,6 +60,18 @@ func initFromConfig(cfg *ForgeConfigs) *Forge { log.Info("ENV changed config. todo: save config here") f.Config.ConfigSave() } + if f.Config.ReposPB != os.Getenv("FORGE_REPOSPB") { + // if different, use the ENV var + // this probably means that it gets saved as the default in the config + // we probably want that (?) + f.Config.ReposPB = os.Getenv("FORGE_REPOSPB") + } + if _, s := filepath.Split(f.Config.ReposPB); s != "repos.pb" { + fhelp.DumpENV("forge:") + f.Config.DumpENV() + log.Infof("ReposPB invalid filename '%s'\n", f.Config.ReposPB) + os.Exit(-1) + } f.Repos = gitpb.NewRepos() f.Repos.ConfigLoad(f.Config.ReposPB) @@ -71,29 +85,22 @@ func initFromConfig(cfg *ForgeConfigs) *Forge { return f } -/* -func (f *Forge) InitMachine() { - if f.Config.Username == "" { - usr, _ := user.Current() - f.Config.Username = usr.Username - } - f.hostname, _ = os.Hostname() - // log.Info(hostname, err) -} -*/ - func (f *Forge) SetConfigSave(b bool) { - f.configSave = b + config.SetChanged("forge", b) } // saves the config if there have been changes func (f *Forge) Exit() { // log.Info("forge.configSave =", f.configSave) - if f.configSave { - f.ConfigSave() + if f.Config.Mode != ForgeMode_NORMAL { + fhelp.DumpENV("forge:") + f.Config.DumpENV() } + + f.ConfigSave() if f.Repos != nil { if config.HasChanged("repos") { + log.Info("TRYING FILENAME:", f.Config.ReposPB) if err := f.Repos.ConfigSave(f.Config.ReposPB); err != nil { log.Info("forge.Repos.ConfigSave() error", err) } @@ -116,7 +123,6 @@ func (f *Forge) setenv() { log.Info("forge.Config() was nil") os.Exit(-1) } - // f.configDir = os.Getenv("FORGE_CONFIG") // f.forgeURL = os.Getenv("FORGE_URL") f.hostname = os.Getenv("HOSTNAME") if os.Getenv("FORGE_GOWORK") == "true" { |
