Browse Source

新增防止sql注入

dcsunny 2 years ago
parent
commit
f670ce153c
1 changed files with 11 additions and 0 deletions
  1. 11 0
      common/sql.go

+ 11 - 0
common/sql.go

@@ -0,0 +1,11 @@
+package common
+
+import "strings"
+
+// SqlStrReplace 防止sql注入
+func SqlStrReplace(str string) string {
+	if strings.Contains(str, "'") {
+		str = strings.Replace(str, "'", "\\'", -1)
+	}
+	return str
+}