Asset.Resource.Data is empty after json.Unmarshal
gleichda opened this issue · 2 comments
gleichda commented
When reading a asset from a file or inline after json.Unmarshal the Asset.Resource.Data
is empty even if the JSON is not:
package main
import (
"encoding/json"
"io/ioutil"
"log"
"google.golang.org/genproto/googleapis/cloud/asset/v1"
)
func main() {
file, err := ioutil.ReadFile("asset.json")
if err != nil {
log.Panic(err)
}
var myAsset asset.Asset
err = json.Unmarshal(file, &myAsset)
if err != nil {
log.Panic(err)
}
log.Printf("%v", myAsset.Resource)
}
With asset.json is
{
"name": "//cloudresourcemanager.googleapis.com/projects/123456789012",
"asset_type": "cloudresourcemanager.googleapis.com/Project",
"resource": {
"version": "v1",
"discovery_document_uri": "https://cloudresourcemanager.googleapis.com/$discovery/rest?version=v1",
"discovery_name": "Project",
"parent": "//cloudresourcemanager.googleapis.com/folders/234567890121",
"data": {
"createTime": "2018-08-08T08:04:36.279Z",
"labels": {
"env": "dev",
"product": "my"
},
"lifecycleState": "ACTIVE",
"name": "my-project",
"parent": {
"id": "234567890121",
"type": "folder"
},
"projectId": "my-project-id",
"projectNumber": "123456789012"
}
},
"ancestors": [
"projects/123456789012",
"folders/234567890121",
"organizations/345678901212"
]
}
Acutal behaviour
$ go run main.go
2020/05/13 11:08:59 version:"v1" discovery_document_uri:"https://cloudresourcemanager.googleapis.com/$discovery/rest?version=v1" discovery_name:"Project" parent:"//cloudresourcemanager.googleapis.com/folders/234567890121" data:<>
Expected behaviour
data
should contain the information about from the json data block.
codyoss commented
Sorry for all of the noise with transferring, could not decide where I wanted this issue. I think the resource you should actually be using in this case is: https://pkg.go.dev/google.golang.org/api/cloudasset/v1?tab=doc#Asset. Which is a different project. That is our REST/JSON based apis.
If you switch your import to asset "google.golang.org/api/cloudasset/v1"
your could will just work.
gleichda commented
Yes works for me. 🎉 Thanks a lot