Skip to content

Commit ffd7d3c

Browse files
committed
Merge pull request #26 from sharonjl/master
Added support for int64 and uint64 primary id types
2 parents a2b98a0 + 04bf044 commit ffd7d3c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

response.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,18 @@ func visitModelNode(model interface{}, included *map[string]*Node, sideload bool
178178
if annotation == "primary" {
179179
id := fieldValue.Interface()
180180

181-
str, ok := id.(string)
182-
if ok {
183-
node.Id = str
184-
} else {
185-
j, ok := id.(int)
186-
if ok {
187-
node.Id = strconv.Itoa(j)
188-
} else {
189-
er = ErrBadJSONAPIID
190-
break
191-
}
181+
switch nId := id.(type) {
182+
case string:
183+
node.Id = nId
184+
case int:
185+
node.Id = strconv.Itoa(nId)
186+
case int64:
187+
node.Id = strconv.FormatInt(nId, 10)
188+
case uint64:
189+
node.Id = strconv.FormatUint(nId, 10)
190+
default:
191+
er = ErrBadJSONAPIID
192+
break
192193
}
193194

194195
node.Type = args[1]

0 commit comments

Comments
 (0)