go - How to interpolate a byte slice? -


i'm attempting build json payload post request:

var payload = []byte(`{"foo":"bar", "hello":"world"}`) 

however, values interpolated existing string. i've tried use %s, not syntactically correct:

var payload = []byte(`{"foo":%s, "hello":%s}`, val1, val2) 

feels i'm going entirely wrong way. suggestions appreciated. thanks.

to use %s, need formatting function.

var payload = []byte(fmt.sprintf(`{"foo":%q, "hello":%q}`, val1, val2)) 

(%q %s adds quotes you)


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -