config.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import parsecfg except Config
  2. import types, strutils
  3. proc get*[T](config: parseCfg.Config; s, v: string; default: T): T =
  4. let val = config.getSectionValue(s, v)
  5. if val.len == 0: return default
  6. when T is int: parseInt(val)
  7. elif T is bool: parseBool(val)
  8. elif T is string: val
  9. proc getConfig*(path: string): (Config, parseCfg.Config) =
  10. var cfg = loadConfig(path)
  11. let conf = Config(
  12. address: cfg.get("Server", "address", "0.0.0.0"),
  13. port: cfg.get("Server", "port", 8080),
  14. useHttps: cfg.get("Server", "https", true),
  15. title: cfg.get("Server", "title", "Nitter"),
  16. hostname: cfg.get("Server", "hostname", "nitter.net"),
  17. staticDir: cfg.get("Server", "staticDir", "./public"),
  18. hmacKey: cfg.get("Config", "hmacKey", "secretkey"),
  19. base64Media: cfg.get("Config", "base64Media", false),
  20. minTokens: cfg.get("Config", "tokenCount", 10),
  21. cacheDir: cfg.get("Cache", "directory", "/tmp/nitter"),
  22. listCacheTime: cfg.get("Cache", "listMinutes", 120),
  23. rssCacheTime: cfg.get("Cache", "rssMinutes", 10),
  24. redisHost: cfg.get("Cache", "redisHost", "localhost"),
  25. redisPort: cfg.get("Cache", "redisPort", 6379),
  26. redisConns: cfg.get("Cache", "redisConnections", 20),
  27. redisMaxConns: cfg.get("Cache", "redisMaxConnections", 30)
  28. )
  29. return (conf, cfg)