Skip to content

Instantly share code, notes, and snippets.

@KaiserWerk
Created November 25, 2021 12:55
Show Gist options
  • Save KaiserWerk/22bd885dcc5351515da0c5364b24ede7 to your computer and use it in GitHub Desktop.
Save KaiserWerk/22bd885dcc5351515da0c5364b24ede7 to your computer and use it in GitHub Desktop.
Add slashes to escape special characters
func Addslashes(str string) string {
var buf bytes.Buffer
for _, char := range str {
switch char {
case `'`, `"`, `\`:
buf.WriteRune(`\`)
}
buf.WriteRune(char)
}
return buf.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment