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

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

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -