Explorar o código

新增防止sql注入

dcsunny %!s(int64=2) %!d(string=hai) anos
pai
achega
f670ce153c
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  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
+}