You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package config
  2. import (
  3. "log"
  4. "os"
  5. "strconv"
  6. "time"
  7. )
  8. func Location() *time.Location {
  9. env, ok := os.LookupEnv("LUCIFER_LOCATION")
  10. if !ok {
  11. return time.UTC
  12. }
  13. loc, err := time.LoadLocation(env)
  14. if err != nil {
  15. log.Printf("Location lookup failed: %s (%s)", env, err.Error())
  16. return time.UTC
  17. }
  18. return loc
  19. }
  20. func MySqlHost() string { return strEnv("LUCIFER_MYSQL_HOST") }
  21. func MySqlPort() int { return intEnv("LUCIFER_MYSQL_PORT") }
  22. func MySqlSchema() string { return strEnv("LUCIFER_MYSQL_SCHEMA") }
  23. func MySqlUsername() string { return strEnv("LUCIFER_MYSQL_USERNAME") }
  24. func MySQlPassword() string { return strEnv("LUCIFER_MYSQL_PASSWORD") }
  25. func ServerPort() int { return intEnv("LUCIFER_SERVER_PORT") }
  26. func strEnv(key string) string {
  27. env, ok := os.LookupEnv(key)
  28. if !ok {
  29. panic("missing environment variable: " + key)
  30. }
  31. return env
  32. }
  33. func intEnv(key string) int {
  34. val, err := strconv.Atoi(strEnv(key))
  35. if err != nil {
  36. panic("invalid environment variable: " + key)
  37. }
  38. return val
  39. }