3
0

Fix actionlog's meta type enc/dec

This commit is contained in:
Denis Arh
2022-02-12 12:27:01 +01:00
parent 1949782ccd
commit e833796aaa
+23
View File
@@ -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)
}