Rename to jwt_full to avoid collision with existing nim-jwt.

This commit is contained in:
jdb committed 2021-12-25 21:24:48 -06:00
1 parent 35a9cf682c
commit 4cc2a4dee5
25 files changed
+30 -30

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import std/json, std/options, std/strutils, std/times
import ./timeutils
func reqStrVal*(n: JsonNode, key: string): string =
if n.hasKey(key):
let val = n[key].getStr("")
if not val.isEmptyOrWhitespace: return val
raise newException(ValueError, "missing value for '" & key & "'")
func optStrVal*(n: JsonNode, key: string): Option[string] =
if n.hasKey(key): some(n[key].getStr)
else: none[string]()
func reqIntVal*(n: JsonNode, key: string): BiggestInt =
if n.hasKey(key):
if n[key].kind == JInt:
return n[key].getBiggestInt
raise newException(ValueError, "value for '" & key & "' is missing or not an integer")
func optIntVal*(n: JsonNode, key: string): Option[BiggestInt] =
if n.hasKey(key) and n[key].kind == JInt:
some(n[key].getBiggestInt)
else: none[BiggestInt]()
proc reqNumericDate*(n: Jsonnode, key: string): DateTime =
fromNumericDate(n.reqIntVal(key))
proc optNumericDate*(n: JsonNode, key: string): Option[DateTime] =
let val = n.optIntVal(key)
if val.isSome: return some(fromNumericDate(val.get))
else: return none[DateTime]()