config.nim 915 B

1234567891011121314151617181920212223242526272829
  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. staticDir: cfg.get("Server", "staticDir", "./public"),
  16. title: cfg.get("Server", "title", "Nitter"),
  17. hostname: cfg.get("Server", "hostname", "nitter.net"),
  18. cacheDir: cfg.get("Cache", "directory", "/tmp/nitter"),
  19. profileCacheTime: cfg.get("Cache", "profileMinutes", 10),
  20. hmacKey: cfg.get("Config", "hmacKey", "secretkey")
  21. )
  22. return (conf, cfg)