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
Post a Comment