nitter/src/config.nim

29 lines
928 B
Nim
Raw Normal View History

2019-07-31 02:23:16 +00:00
import parsecfg except Config
2019-08-13 17:44:29 +00:00
import net, types, strutils
2019-07-31 02:23:16 +00:00
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),
useHttps: cfg.get("Server", "https", true),
2019-07-31 02:23:16 +00:00
staticDir: cfg.get("Server", "staticDir", "./public"),
title: cfg.get("Server", "title", "Nitter"),
hostname: cfg.get("Server", "hostname", "nitter.net"),
2019-07-31 02:23:16 +00:00
cacheDir: cfg.get("Cache", "directory", "/tmp/nitter"),
2019-10-23 12:06:47 +00:00
profileCacheTime: cfg.get("Cache", "profileMinutes", 10),
defaultTheme: cfg.get("Config", "defaultTheme", "Dark"),
hmacKey: cfg.get("Config", "hmacKey", "secretkey")
2019-07-31 02:23:16 +00:00
)