I have created a webserver that receives POST requests, creates a txt file and prints it using the lp command.
However, those strings coming from a request that contains "\n" are saved into the file with \n as a text instead of creating a line break.
If I declare a hard-coding string, the line breaks are created.
This is the relevant code:
func handler(w http.ResponseWriter, r *http.Request) {
bodyBuffer, _ := ioutil.ReadAll(r.Body)
err := ioutil.WriteFile("/tmp/print.txt", bodyBuffer, 0644)
//... More code
}
If I run this command:
curl -X POST --data "My\nName" http://127.0.0.1:8080/
The text file generated contains: My\nName instead of two lines.