I wrote a web service (golang) using the gin framework to receive parameters in json body format. I make a request like this:
curl --location 'http://foo.bar/test' \
--header 'Content-Type: application/json' \
--data'{
"a": "1",
"b": "2"
}'
Now, I added a middleware that prints all request parameters to a log file, which runs one layer above the controller. Note that the specific type of the parameter is not known at the middleware layer. When I read the body and print the log, I get the following result:
[2023/06/20 11:44:38 CST] [INFO] (.../infra/log.Info:18) request_in||traceid=xx||spanid=xxx||path=/test||body= {
"a": "1",
"b": "2"
}
I expect something like this:
[2023/06/20 11:44:38 CST] [INFO] (/infra/log.Info:18) request_in||traceid=xx||spanid=xxx||path=/test||body={"a ":"1","b":"2"}
I would like to ask: How to remove the spaces and line breaks in the body? Note that the body parameter in this example is relatively simple, but the actual situation will be more complicated. Thanks.