Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit ec041eb

Browse files
authored
Updated README.md
Corrected the example for Links
1 parent 7d60f15 commit ec041eb

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,25 @@ func CreateBlogs(w http.ResponseWriter, r *http.Request) {
342342
If you need to include [link objects](http://jsonapi.org/format/#document-links) along with response data, implement the `Linkable` interface for document-links, and `RelationshipLinkable` for relationship links:
343343

344344
```go
345-
func (post Post) JSONAPILinks() *map[string]interface{} {
346-
return &map[string]interface{}{
345+
func (post Post) JSONAPILinks() *Links {
346+
return &Links{
347347
"self": "href": fmt.Sprintf("https://example.com/posts/%d", post.ID),
348+
"comments": Link{
349+
Href: fmt.Sprintf("https://example.com/api/blogs/%d/comments", post.ID),
350+
Meta: map[string]interface{}{
351+
"counts": map[string]uint{
352+
"likes": 4,
353+
},
354+
},
355+
},
348356
}
349357
}
350358

351359
// Invoked for each relationship defined on the Post struct when marshaled
352-
func (post Post) JSONAPIRelationshipLinks(relation string) *map[string]interface{} {
360+
func (post Post) JSONAPIRelationshipLinks(relation string) *Links {
353361
if relation == "comments" {
354-
return &map[string]interface{}{
355-
"related": fmt.Sprintf("https://example.com/posts/%d/comments", post.ID),
362+
return &Links{
363+
"related": fmt.Sprintf("https://example.com/posts/%d/comments", post.ID),
356364
}
357365
}
358366
return nil

0 commit comments

Comments
 (0)