config.go 620 B

123456789101112131415161718192021222324252627282930313233343536
  1. package config
  2. import (
  3. "log"
  4. "os"
  5. "github.com/joho/godotenv"
  6. )
  7. type config struct {
  8. Redis string
  9. Token string
  10. Channel string
  11. AdminChats []int64
  12. }
  13. var conf *config = nil
  14. func Get() *config {
  15. if nil == conf {
  16. err := godotenv.Load(".env")
  17. if err != nil {
  18. log.Printf("[config]: .env parse failed")
  19. }
  20. var configInstance config
  21. configInstance.Redis = os.Getenv("REDIS")
  22. configInstance.Token = os.Getenv("BOT_TOKEN")
  23. configInstance.Channel = os.Getenv("CHANNEL")
  24. configInstance.AdminChats = append(configInstance.AdminChats, 388107612)
  25. conf = &configInstance
  26. }
  27. return conf
  28. }