Skip to content

Instantly share code, notes, and snippets.

@erayakartuna
Last active January 2, 2022 19:19
Show Gist options
  • Save erayakartuna/13fdf6e1dbecaa56d37cb5ab9bb5923c to your computer and use it in GitHub Desktop.
Save erayakartuna/13fdf6e1dbecaa56d37cb5ab9bb5923c to your computer and use it in GitHub Desktop.
Save Logging
// SaveRequest with request and response
func SaveRequest(url string, reqBody string, respStatus int, resp string) {
r := fmt.Sprintf(
`{"url": "%s", "reqBody": "%s", "respStatus": "%d", "resp": "%s"\n`,
jsonEscape(url),
jsonEscape(reqBody),
respStatus,
jsonEscape(resp),
)
logs.Lock()
logs.responses = append(logs.responses, r)
logs.Unlock()
}
// jsonEscape ...
func jsonEscape(i string) string {
b, err := json.Marshal(i)
if err != nil {
Fatal(err)
}
s := string(b)
return s[1 : len(s)-1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment