config.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. Notice LogLevel = "notice"
  17. Warn LogLevel = "warn"
  18. Error LogLevel = "error"
  19. )
  20. func GetVersion() string {
  21. return strings.TrimSpace(version)
  22. }
  23. func GetName() string {
  24. return strings.TrimSpace(name)
  25. }
  26. func GetLogLevel() LogLevel {
  27. if IsDebug() {
  28. return Debug
  29. }
  30. logLevel := os.Getenv("XUI_LOG_LEVEL")
  31. if logLevel == "" {
  32. return Info
  33. }
  34. return LogLevel(logLevel)
  35. }
  36. func IsDebug() bool {
  37. return os.Getenv("XUI_DEBUG") == "true"
  38. }
  39. func GetBinFolderPath() string {
  40. binFolderPath := os.Getenv("XUI_BIN_FOLDER")
  41. if binFolderPath == "" {
  42. binFolderPath = "bin"
  43. }
  44. return binFolderPath
  45. }
  46. func GetDBFolderPath() string {
  47. dbFolderPath := os.Getenv("XUI_DB_FOLDER")
  48. if dbFolderPath == "" {
  49. dbFolderPath = "/etc/x-ui"
  50. }
  51. return dbFolderPath
  52. }
  53. func GetDBPath() string {
  54. return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
  55. }