I was wondering what would be the most elegant way to write a Key Value Form encoded map to a http.ResponseWriter.
Respond(kv map[string]string) {
for key, value := range kv {
fmt.Fprintf(a.w, "%s:%s
", key, value)
}
}
I have to follow this Key-Value format:
Key-Value Form Encoding
A message in Key-Value form is a sequence of lines. Each line begins with a key, followed by a colon, and the value associated with the key. The line is terminated by a single newline (UCS codepoint 10, " "). A key or value MUST NOT contain a newline and a key also MUST NOT contain a colon.
Additional characters, including whitespace, MUST NOT be added before or after the colon or newline. The message MUST be encoded in UTF-8 to produce a byte string.
I thought about using encoding/csv but isn't that a bit overkill?
Edit: What I came up with so far. (Thanks for all the suggested answers)