77 "github.com/google/jsonapi"
88)
99
10+ // Blog is a model representing a blog site
1011type Blog struct {
1112 ID int `jsonapi:"primary,blogs"`
1213 Title string `jsonapi:"attr,title"`
@@ -17,6 +18,7 @@ type Blog struct {
1718 ViewCount int `jsonapi:"attr,view_count"`
1819}
1920
21+ // Post is a model representing a post on a blog
2022type Post struct {
2123 ID int `jsonapi:"primary,posts"`
2224 BlogID int `jsonapi:"attr,blog_id"`
@@ -25,19 +27,21 @@ type Post struct {
2527 Comments []* Comment `jsonapi:"relation,comments"`
2628}
2729
30+ // Comment is a model representing a user submitted comment
2831type Comment struct {
2932 ID int `jsonapi:"primary,comments"`
3033 PostID int `jsonapi:"attr,post_id"`
3134 Body string `jsonapi:"attr,body"`
3235}
3336
34- // Blog Links
37+ // JSONAPILinks implements the Linkable interface for a blog
3538func (blog Blog ) JSONAPILinks () * jsonapi.Links {
3639 return & jsonapi.Links {
3740 "self" : fmt .Sprintf ("https://example.com/blogs/%d" , blog .ID ),
3841 }
3942}
4043
44+ // JSONAPIRelationshipLinks implements the RelationshipLinkable interface for a blog
4145func (blog Blog ) JSONAPIRelationshipLinks (relation string ) * jsonapi.Links {
4246 if relation == "posts" {
4347 return & jsonapi.Links {
@@ -52,13 +56,14 @@ func (blog Blog) JSONAPIRelationshipLinks(relation string) *jsonapi.Links {
5256 return nil
5357}
5458
55- // Blog Meta
59+ // JSONAPIMeta implements the Metable interface for a blog
5660func (blog Blog ) JSONAPIMeta () * jsonapi.Meta {
5761 return & jsonapi.Meta {
5862 "detail" : "extra details regarding the blog" ,
5963 }
6064}
6165
66+ // JSONAPIRelationshipMeta implements the RelationshipMetable interface for a blog
6267func (blog Blog ) JSONAPIRelationshipMeta (relation string ) * jsonapi.Meta {
6368 if relation == "posts" {
6469 return & jsonapi.Meta {
0 commit comments