From e833796aaadc1493e7f2f84e1cdd706b7659c7e3 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Sat, 12 Feb 2022 12:27:01 +0100 Subject: [PATCH] Fix actionlog's meta type enc/dec --- pkg/actionlog/types.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/actionlog/types.go b/pkg/actionlog/types.go index b5043eddf..0ca7da1bf 100644 --- a/pkg/actionlog/types.go +++ b/pkg/actionlog/types.go @@ -1,8 +1,12 @@ package actionlog import ( + "database/sql/driver" + "encoding/json" "strconv" "time" + + "github.com/pkg/errors" ) type ( @@ -227,3 +231,22 @@ func NewSeverity(s string) Severity { return Debug } + +func (m *Meta) Scan(value interface{}) error { + //lint:ignore S1034 This typecast is intentional, we need to get []byte out of a []uint8 + switch value.(type) { + case nil: + *m = Meta{} + case []uint8: + aux := value.([]byte) + if err := json.Unmarshal(aux, m); err != nil { + return errors.Wrapf(err, "cannot scan '%v' into Meta", string(aux)) + } + } + + return nil +} + +func (m Meta) Value() (driver.Value, error) { + return json.Marshal(m) +}