Skip to content

Commit 893bd20

Browse files
chore: update scan function
1 parent 176bcbf commit 893bd20

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

pkg/types/integration.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ type AccountConfig struct {
112112

113113
// For serializing from db
114114
func (c *AccountConfig) Scan(src any) error {
115-
data, ok := src.([]byte)
116-
if !ok {
117-
return fmt.Errorf("tried to scan from %T instead of bytes", src)
115+
var data []byte
116+
switch v := src.(type) {
117+
case []byte:
118+
data = v
119+
case string:
120+
data = []byte(v)
121+
default:
122+
return fmt.Errorf("tried to scan from %T instead of string or bytes", src)
118123
}
119124

120125
return json.Unmarshal(data, &c)
@@ -142,9 +147,14 @@ type AgentReport struct {
142147

143148
// For serializing from db
144149
func (r *AgentReport) Scan(src any) error {
145-
data, ok := src.([]byte)
146-
if !ok {
147-
return fmt.Errorf("tried to scan from %T instead of bytes", src)
150+
var data []byte
151+
switch v := src.(type) {
152+
case []byte:
153+
data = v
154+
case string:
155+
data = []byte(v)
156+
default:
157+
return fmt.Errorf("tried to scan from %T instead of string or bytes", src)
148158
}
149159

150160
return json.Unmarshal(data, &r)

0 commit comments

Comments
 (0)