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

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -