()
| 44 | } |
| 45 | |
| 46 | func ExampleMarshal_meta() { |
| 47 | type ArticleMeta struct { |
| 48 | Views int `json:"views"` |
| 49 | } |
| 50 | type Article struct { |
| 51 | ID string `jsonapi:"primary,articles"` |
| 52 | Title string `jsonapi:"attribute" json:"title"` |
| 53 | Meta *ArticleMeta `jsonapi:"meta"` |
| 54 | } |
| 55 | |
| 56 | a := Article{ID: "1", Title: "Hello World", Meta: &ArticleMeta{Views: 10}} |
| 57 | m := map[string]any{"foo": "bar"} |
| 58 | |
| 59 | b, err := jsonapi.Marshal(&a, jsonapi.MarshalMeta(m)) |
| 60 | if err != nil { |
| 61 | panic(err) |
| 62 | } |
| 63 | |
| 64 | fmt.Printf("%s", string(b)) |
| 65 | // Output: {"data":{"id":"1","type":"articles","attributes":{"title":"Hello World"},"meta":{"views":10}},"meta":{"foo":"bar"}} |
| 66 | } |
nothing calls this directly
no test coverage detected