Last active
January 2, 2022 19:19
-
-
Save erayakartuna/13fdf6e1dbecaa56d37cb5ab9bb5923c to your computer and use it in GitHub Desktop.
Save Logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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