Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
45 lines
1 KiB
Go
45 lines
1 KiB
Go
package env
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/xfilepath"
|
|
)
|
|
|
|
const (
|
|
DebugEnvVar = "IGNT_DEBUG"
|
|
ConfigDirEnvVar = "IGNT_CONFIG_DIR"
|
|
)
|
|
|
|
// SetDebug sets the debug environment variable to "1".
|
|
// This is used to enable debug mode in the application.
|
|
func SetDebug() {
|
|
_ = os.Setenv(DebugEnvVar, "1")
|
|
}
|
|
|
|
// IsDebug checks if the debug environment variable is set to "1".
|
|
// This is used to determine if the application is running in debug mode.
|
|
func IsDebug() bool {
|
|
return os.Getenv(DebugEnvVar) == "1"
|
|
}
|
|
|
|
func ConfigDir() xfilepath.PathRetriever {
|
|
return func() (string, error) {
|
|
if dir := os.Getenv(ConfigDirEnvVar); dir != "" {
|
|
if !path.IsAbs(dir) {
|
|
panic(fmt.Sprintf("%s must be an absolute path", ConfigDirEnvVar))
|
|
}
|
|
return dir, nil
|
|
}
|
|
return xfilepath.JoinFromHome(xfilepath.Path(".ignite"))()
|
|
}
|
|
}
|
|
|
|
func SetConfigDir(dir string) {
|
|
err := os.Setenv(ConfigDirEnvVar, dir)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("set config dir env: %v", err))
|
|
}
|
|
}
|