Source code of DERO Merchant
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

104 lines
3.0KB

  1. package config
  2. import (
  3. "os"
  4. "strconv"
  5. "strings"
  6. "github.com/joho/godotenv"
  7. "github.com/pkg/errors"
  8. )
  9. // ServerPort is the port the web server will listen to
  10. var ServerPort int
  11. // PostgresSQL database config
  12. var (
  13. DBName string
  14. DBUser string
  15. DBPassword string
  16. DBHost string
  17. DBPort int
  18. )
  19. // RedisAddress is the host:port of the Redis server the application will connect to
  20. var RedisAddress string
  21. // Dero Network, wallet and payments config
  22. var (
  23. // DeroNetwork is either mainnet or testnet
  24. DeroNetwork string
  25. // DeroDaemonAddress is the host:port of the (possibly remote) node active wallets will connect to
  26. DeroDaemonAddress string
  27. // WalletsPath is the relative path of the directory where active wallets files will be stored
  28. WalletsPath string
  29. // PaymentMaxTTL is the MAX number of MINUTES allowed to receive payment before it expires
  30. PaymentMaxTTL int
  31. // PaymentMinConfirmations is the MINIMUM number of confirmations a payment needs to have before it is considered valid
  32. PaymentMinConfirmations int
  33. )
  34. // Config for testing
  35. var (
  36. TestDBName string
  37. TestDBUser string
  38. TestDBPassword string
  39. TestDBHost string
  40. TestDBPort int
  41. TestRedisAddress string
  42. TestDeroNetwork string
  43. TestDeroDaemonAddress string
  44. TestWalletsPath string
  45. )
  46. // LoadFromENV loads the config from .env file
  47. func LoadFromENV(filenames ...string) error {
  48. err := godotenv.Load(filenames...)
  49. if err != nil {
  50. return errors.Wrap(err, "cannot load godotenv .env file")
  51. }
  52. ServerPort, err = strconv.Atoi(os.Getenv("PORT"))
  53. if err != nil {
  54. return errors.Wrap(err, "cannot convert string to integer")
  55. }
  56. DBName = os.Getenv("DB_NAME")
  57. DBUser = os.Getenv("DB_USER")
  58. DBPassword = os.Getenv("DB_PASSWORD")
  59. DBHost = os.Getenv("DB_HOST")
  60. DBPort, err = strconv.Atoi(os.Getenv("DB_PORT"))
  61. if err != nil {
  62. return errors.Wrap(err, "cannot convert string to integer")
  63. }
  64. RedisAddress = os.Getenv("REDIS_ADDRESS")
  65. DeroNetwork = strings.ToLower(os.Getenv("DERO_NETWORK"))
  66. DeroDaemonAddress = os.Getenv("DERO_DAEMON_ADDRESS")
  67. WalletsPath = os.Getenv("WALLETS_PATH")
  68. PaymentMaxTTL, err = strconv.Atoi(os.Getenv("PAYMENT_MAX_TTL"))
  69. if err != nil {
  70. return errors.Wrap(err, "cannot convert string to integer")
  71. }
  72. PaymentMinConfirmations, err = strconv.Atoi(os.Getenv("PAYMENT_MIN_CONFIRMATIONS"))
  73. if err != nil {
  74. return errors.Wrap(err, "cannot convert string to integer")
  75. }
  76. TestDBName = os.Getenv("TEST_DB_NAME")
  77. TestDBUser = os.Getenv("TEST_DB_USER")
  78. TestDBPassword = os.Getenv("TEST_DB_PASSWORD")
  79. TestDBHost = os.Getenv("TEST_DB_HOST")
  80. TestDBPort, err = strconv.Atoi(os.Getenv("TEST_DB_PORT"))
  81. if err != nil {
  82. return errors.Wrap(err, "cannot convert string to integer")
  83. }
  84. TestRedisAddress = os.Getenv("TEST_REDIS_ADDRESS")
  85. TestDeroNetwork = strings.ToLower(os.Getenv("TEST_DERO_NETWORK"))
  86. TestDeroDaemonAddress = os.Getenv("TEST_DERO_DAEMON_ADDRESS")
  87. TestWalletsPath = os.Getenv("TEST_WALLETS_PATH")
  88. return nil
  89. }