config.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package config
  2. import (
  3. _ "embed"
  4. "fmt"
  5. "os"
  6. "strings"
  7. )
  8. //go:embed version
  9. var version string
  10. //go:embed name
  11. var name string
  12. type LogLevel string
  13. const (
  14. Debug LogLevel = "debug"
  15. Info LogLevel = "info"
  16. Warn LogLevel = "warn"
  17. Error LogLevel = "error"
  18. )
  19. func GetVersion() string {
  20. return strings.TrimSpace(version)
  21. }
  22. func GetName() string {
  23. return strings.TrimSpace(name)
  24. }
  25. func GetLogLevel() LogLevel {
  26. if IsDebug() {
  27. return Debug
  28. }
  29. logLevel := os.Getenv("XUI_LOG_LEVEL")
  30. if logLevel == "" {
  31. return Info
  32. }
  33. return LogLevel(logLevel)
  34. }
  35. func IsDebug() bool {
  36. return os.Getenv("XUI_DEBUG") == "true"
  37. }
  38. func GetBinFolderPath() string {
  39. binFolderPath := os.Getenv("XUI_BIN_FOLDER")
  40. if binFolderPath == "" {
  41. binFolderPath = "bin"
  42. }
  43. return binFolderPath
  44. }
  45. func GetDBFolderPath() string {
  46. dbFolderPath := os.Getenv("XUI_DB_FOLDER")
  47. if dbFolderPath == "" {
  48. dbFolderPath = "/etc/x-ui"
  49. }
  50. return dbFolderPath
  51. }
  52. func GetDBPath() string {
  53. return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
  54. }