IBM / cloudant-go-sdk

Cloudant SDK for Go
Apache License 2.0
21 stars 12 forks source link

How can we convert response of dbClient.PostFind(postFindOptions) into struct? #298

Closed ghost closed 2 years ago

ghost commented 2 years ago

I am unable to convert the response into struct. below is my code .. findResult, , err := dbClient.PostFind(postFindOptions) if err != nil { fmt.Println("err", err) } b, := json.MarshalIndent(findResult, "", " ")

how can we convert findResult into struct? please suggest the solution.

Thanks in advanced!

ricellis commented 2 years ago

The findResult is a FindResult struct, that is what is returned by PostFind.

ghost commented 2 years ago

Thanks Rich for your quick reply. Actually I am getting 'Docs' from FindResult struct and want to have docs values in my customized struct where i can apply my logic.

ricellis commented 2 years ago

Actually I am getting 'Docs' from FindResult struct and want to have docs values in my customized struct where i can apply my logic.

Sorry that wasn't clear to me from the original question.

You have 2 choices:

  1. write a converter to accept the built-in Document struct type and use GetProperty/GetProperties to retrieve the properties you need and apply them to your own struct type.
  2. use raw IO with PostFindAsStream to bypass the built-in types and deserialize directly into your own structs.