3535 LogSink func (* g.LogLine )
3636 TelMap = g .M ("begin_time" , time .Now ().UnixMicro ())
3737 TelMux = sync.Mutex {}
38- HomeDirs = map [string ]string {}
3938 envMux = sync.Mutex {}
4039 NoDebugKey = " /* nD */"
4140 Executable = ""
@@ -99,25 +98,13 @@ const (
9998var envFolder embed.FS
10099
101100func init () {
102-
103- HomeDir = SetHomeDir ("sling" )
104- HomeDirEnvFile = GetEnvFilePath (HomeDir )
105101 Executable , _ = osext .Executable ()
106102
107- // create env file if not exists
108- os .MkdirAll (HomeDir , 0755 )
109- if HomeDir != "" && ! g .PathExists (HomeDirEnvFile ) {
110- defaultEnvBytes , _ := envFolder .ReadFile ("default.env.yaml" )
111- os .WriteFile (HomeDirEnvFile , defaultEnvBytes , 0644 )
112- }
113-
114103 if content := os .Getenv ("SLING_ENV_YAML" ); content != "" {
115104 os .Setenv ("ENV_YAML" , content )
116105 }
117106
118- // other sources of creds
119- SetHomeDir ("dbnet" ) // https://github.com/dbnet-io/dbnet
120- SetHomeDir ("dbrest" ) // https://github.com/dbrest-io/dbrest
107+ LoadHomeDir ()
121108
122109 if SentryDsn == "" {
123110 SentryDsn = os .Getenv ("SENTRY_DSN" )
@@ -139,6 +126,24 @@ func init() {
139126 }
140127}
141128
129+ func LoadHomeDir () {
130+ envKey := "SLING_HOME_DIR"
131+ HomeDir = CleanWindowsPath (os .Getenv (envKey ))
132+ if HomeDir == "" {
133+ HomeDir = CleanWindowsPath (path .Join (g .UserHomeDir (), ".sling" ))
134+ os .Setenv (envKey , HomeDir )
135+ }
136+
137+ HomeDirEnvFile = GetEnvFilePath (HomeDir )
138+
139+ // create env file if not exists
140+ os .MkdirAll (HomeDir , 0755 )
141+ if HomeDir != "" && ! g .PathExists (HomeDirEnvFile ) {
142+ defaultEnvBytes , _ := envFolder .ReadFile ("default.env.yaml" )
143+ os .WriteFile (HomeDirEnvFile , defaultEnvBytes , 0644 )
144+ }
145+ }
146+
142147func HomeBinDir () string {
143148 return path .Join (HomeDir , "bin" )
144149}
@@ -619,15 +624,13 @@ func GetHomeDirConnsMap() (connsMap map[string]map[string]any, err error) {
619624 defer envMux .Unlock ()
620625 envMux .Lock ()
621626 connsMap = map [string ]map [string ]any {}
622- for _ , homeDir := range HomeDirs {
623- envFilePath := GetEnvFilePath (homeDir )
624- if g .PathExists (envFilePath ) {
625- m := g .M ()
626- g .JSONConvert (LoadEnvFile (envFilePath ), & m )
627- cm , _ := readConnectionsMap (m )
628- for k , v := range cm {
629- connsMap [k ] = v
630- }
627+ envFilePath := GetEnvFilePath (HomeDir )
628+ if g .PathExists (envFilePath ) {
629+ m := g .M ()
630+ g .JSONConvert (LoadEnvFile (envFilePath ), & m )
631+ cm , _ := readConnectionsMap (m )
632+ for k , v := range cm {
633+ connsMap [k ] = v
631634 }
632635 }
633636 return connsMap , nil
0 commit comments