From d0ee8e8403635a0079afe069147d017bb2b513b1 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 31 Jul 2019 04:23:16 +0200 Subject: [PATCH] Add missing config file --- src/config.nim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/config.nim diff --git a/src/config.nim b/src/config.nim new file mode 100644 index 0000000..34cd1f3 --- /dev/null +++ b/src/config.nim @@ -0,0 +1,23 @@ +import parsecfg except Config +import os, net, types, strutils + +proc get[T](config: parseCfg.Config; s, v: string; default: T): T = + let val = config.getSectionValue(s, v) + if val.len == 0: return default + + when T is int: parseInt(val) + elif T is bool: parseBool(val) + elif T is string: val + +proc getConfig*(path: string): Config = + var cfg = loadConfig(path) + + Config( + address: cfg.get("Server", "address", "0.0.0.0"), + port: cfg.get("Server", "port", 8080), + title: cfg.get("Server", "title", "Nitter"), + staticDir: cfg.get("Server", "staticDir", "./public"), + + cacheDir: cfg.get("Cache", "directory", "/tmp/nitter"), + profileCacheTime: cfg.get("Cache", "profileMinutes", 10) + )