3x-ui/config/config.go

68 lines
1.0 KiB
Go
Raw Normal View History

2023-02-09 22:18:06 +03:00
package config
import (
_ "embed"
"fmt"
"os"
"strings"
)
//go:embed version
var version string
//go:embed name
var name string
type LogLevel string
const (
2023-06-16 17:55:33 +03:00
Debug LogLevel = "debug"
Info LogLevel = "info"
Notice LogLevel = "notice"
Warn LogLevel = "warn"
Error LogLevel = "error"
2023-02-09 22:18:06 +03:00
)
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"
}
2023-04-13 22:33:46 +03:00
func GetBinFolderPath() string {
binFolderPath := os.Getenv("XUI_BIN_FOLDER")
if binFolderPath == "" {
binFolderPath = "bin"
}
return binFolderPath
}
func GetDBFolderPath() string {
dbFolderPath := os.Getenv("XUI_DB_FOLDER")
if dbFolderPath == "" {
dbFolderPath = "/etc/x-ui"
}
return dbFolderPath
}
2023-02-09 22:18:06 +03:00
func GetDBPath() string {
2023-04-13 22:33:46 +03:00
return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
2023-02-09 22:18:06 +03:00
}