You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,10 +49,11 @@ comments that belong with a has-many relation to the post.
49
49
50
50
```go
51
51
typePoststruct {
52
-
IDint
52
+
IDint`jsonapi:"-"`// Ignore ID field because the ID is fetched via the
53
+
// GetID() method and must not be inside the attributes object.
53
54
Titlestring
54
-
Comments []Comment`json:"-"`// this will be ignored by the api2go marshaller
55
-
CommentsIDs []int`json:"-"`// it's only useful for our internal relationship handling
55
+
Comments []Comment`jsonapi:"-"`// this will be ignored by the api2go marshaller
56
+
CommentsIDs []int`jsonapi:"-"`// it's only useful for our internal relationship handling
56
57
}
57
58
58
59
typeCommentstruct {
@@ -65,8 +66,9 @@ You must at least implement one interface for api2go to work, which is the one f
65
66
that you want to marshal/unmarshal. This is because of the huge variety of types that you could use for the primary ID. For example a string,
66
67
a UUID or a BSON Object for MongoDB etc...
67
68
68
-
If the struct already has a field named `ID`, or `Id`, it will be ignored automatically. If your ID field has a different name, please use the
69
-
json ignore tag. Api2go will use the `GetID` method that you implemented for your struct to fetch the ID of the struct.
69
+
In the Post example struct, the `ID` field is ignored because Api2go will use the `GetID` method that you implemented for your struct to fetch the ID of the struct.
70
+
Every field inside a struct will be marshaled into the `attributes` object in
71
+
the json. In our example, we just want to have the `Title` field there.
70
72
71
73
In order to use different internal names for elements, you can specify a jsonapi tag. The api will marshal results now with the name in the tag.
72
74
Create/Update/Delete works accordingly, but will fallback to the internal value as well if possible.
0 commit comments