config.nim 751 B

123456789101112131415161718192021222324
  1. import parsecfg except Config
  2. import net, 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 =
  10. var cfg = loadConfig(path)
  11. 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. staticDir: cfg.get("Server", "staticDir", "./public"),
  17. cacheDir: cfg.get("Cache", "directory", "/tmp/nitter"),
  18. profileCacheTime: cfg.get("Cache", "profileMinutes", 10)
  19. )