From f14dc3107f58561b7cff63a8e9b695183aea03cf Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 23 Dec 2017 00:55:36 +0100 Subject: [PATCH] logger: implement json.Unmarshaler refs #10 --- logger/datastructures.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/logger/datastructures.go b/logger/datastructures.go index 745582e..4a58895 100644 --- a/logger/datastructures.go +++ b/logger/datastructures.go @@ -15,6 +15,15 @@ func (l Level) MarshalJSON() ([]byte, error) { return json.Marshal(l.String()) } +func (l *Level) UnmarshalJSON(input []byte) (err error) { + var s string + if err = json.Unmarshal(input, &s); err != nil { + return err + } + *l, err = ParseLevel(s) + return err +} + const ( Debug Level = iota Info