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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -