From ee62850a9c97947bd8258fdccc3b24adee03e282 Mon Sep 17 00:00:00 2001 From: Uros Trebec Date: Fri, 7 May 2021 09:22:53 +0200 Subject: [PATCH 1/2] Allow `ContentFieldsAPIResponse.Data` to hold nested objects By using a generic `interface{}` instead of a `string` ContentFieldsAPIResponse type can be used to unmarshall ContentFields with nested objects, not just strings. For example, this kind of response would throw an error before: ```json { "data": [ { "name": "some name", "complex-object": { "content": "content" } } ] } ``` --- api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.go b/api.go index d5faf23..0d31de0 100644 --- a/api.go +++ b/api.go @@ -72,5 +72,5 @@ type FeedAPIResponse struct { // Content Fields type ContentFieldsAPIResponse struct { - Data map[string]string `json:"data"` + Data map[string]interface{} `json:"data"` } From fbe574b36d043be9bb382e6ac6735b41cae46d68 Mon Sep 17 00:00:00 2001 From: Uros Trebec Date: Fri, 7 May 2021 09:26:31 +0200 Subject: [PATCH 2/2] Add `GetContentFields` usage to the example in README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 4d40f7b..ea9bbb2 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ package main import ( "github.com/buttercms/buttercms-go" "fmt" + "encoding/json" ) func main() { @@ -112,6 +113,20 @@ func main() { } } } + + contentParams := map[string]string{} + contentKeys := []string{"somethings"} + contentResp, err := ButterCMS.GetContentFields(contentKeys, contentParams) + if err != nil { + panic(err.Error()) + } + + j, err := json.Marshal(contentResp) + if err != nil { + fmt.Println(err) + } + + fmt.Println(string(j)) } ```