config.go 628 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package config
  5. import (
  6. "os"
  7. "strconv"
  8. )
  9. const (
  10. DefaultBaseURL = "http://localhost"
  11. )
  12. type Config struct {
  13. }
  14. func (c *Config) Get(key, fallback string) string {
  15. value := os.Getenv(key)
  16. if value == "" {
  17. return fallback
  18. }
  19. return value
  20. }
  21. func (c *Config) GetInt(key string, fallback int) int {
  22. value := os.Getenv(key)
  23. if value == "" {
  24. return fallback
  25. }
  26. v, _ := strconv.Atoi(value)
  27. return v
  28. }
  29. func NewConfig() *Config {
  30. return &Config{}
  31. }