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!


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo