From b73e4173a3c1e69e02ad6b4e3b43e425e57a5be9 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Thu, 9 Feb 2023 22:48:06 +0330 Subject: 3x-ui --- config/config.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ config/name | 1 + config/version | 1 + 3 files changed, 52 insertions(+) create mode 100644 config/config.go create mode 100644 config/name create mode 100644 config/version (limited to 'config') diff --git a/config/config.go b/config/config.go new file mode 100644 index 00000000..e1c7f911 --- /dev/null +++ b/config/config.go @@ -0,0 +1,50 @@ +package config + +import ( + _ "embed" + "fmt" + "os" + "strings" +) + +//go:embed version +var version string + +//go:embed name +var name string + +type LogLevel string + +const ( + Debug LogLevel = "debug" + Info LogLevel = "info" + Warn LogLevel = "warn" + Error LogLevel = "error" +) + +func GetVersion() string { + return strings.TrimSpace(version) +} + +func GetName() string { + return strings.TrimSpace(name) +} + +func GetLogLevel() LogLevel { + if IsDebug() { + return Debug + } + logLevel := os.Getenv("XUI_LOG_LEVEL") + if logLevel == "" { + return Info + } + return LogLevel(logLevel) +} + +func IsDebug() bool { + return os.Getenv("XUI_DEBUG") == "true" +} + +func GetDBPath() string { + return fmt.Sprintf("/etc/%s/%s.db", GetName(), GetName()) +} diff --git a/config/name b/config/name new file mode 100644 index 00000000..491114af --- /dev/null +++ b/config/name @@ -0,0 +1 @@ +x-ui \ No newline at end of file diff --git a/config/version b/config/version new file mode 100644 index 00000000..be14282b --- /dev/null +++ b/config/version @@ -0,0 +1 @@ +0.5.3 -- cgit v1.2.3