json - Unmarshall PubSub Request Data []bytes with Golang -
i have end-point receives data google pubsub request. per this repo, object so:
type pushrequest struct { message struct { attributes map[string]string data []byte id string `json:"message_id"` } subscription string }
the data field consistently formatted so:
type data struct { key string `json:"key"` body string `json:"body"` meta map[string]interface{} `json:"meta"` }
i can obvious unmarshal json request this:
f := &pushrequest{} json.unmarshal(msg, &f)
that leaves the []bytes field. can convert string, per docs
messages = append(messages, string(f.message.data))
which doesn't help, since need struct.
i can unmarshal array again:
var m data json.unmarshal(f.message.data, &m)
have tried changing field type in pushrequest struct data without success. blank...
is there way can unpack things in single pass? doing twice seems ridiculous.
if it's obvious, cant see it!