修复sql语句单引号的问题

master
a74589669 2019-10-06 01:25:44 +08:00
parent 4e2ff25d38
commit 0d27f524ed
3 changed files with 13 additions and 4 deletions

View File

@ -83,7 +83,14 @@ func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
return _db
}
func initMongoDb(conf *config.MongoConfig) *mgo.Session{
url := fmt.Sprintf("mongodb://%s:%s@%s:%d/%s",conf.UserName,conf.Password,conf.Addr,conf.Port,conf.Db)
var url string
if conf.UserName == ""{
url = fmt.Sprintf("mongodb://%s:%d/%s",conf.Addr,conf.Port,conf.Db)
}else{
url = fmt.Sprintf("mongodb://%s:%s@%s:%d/%s",conf.UserName,conf.Password,conf.Addr,conf.Port,conf.Db)
}
log.Print("connect to url " + url)
logs.Debug("connect to url " + url)
@ -111,5 +118,4 @@ func InitMongoDb() {
log.Print("error mongo initial")
os.Exit(25)
}
}

View File

@ -44,7 +44,8 @@ func InitLogs() {
}
func CORSMiddleware(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080")
c.Writer.Header().Set("Access-Control-Allow-Origin",
"http://172.21.102.193:8080")
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
c.Writer.Header().Set("Access-Control-Allow-Headers",
"X-Requested-With," +

View File

@ -4,6 +4,7 @@ import (
"background/db"
"background/logs"
"fmt"
"strings"
)
type Doc struct {
@ -50,7 +51,8 @@ WHERE
func UpdateDoc(doc Doc) error{
sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' where doc.id = '%d'; `,
doc.Author, doc.Title, doc.Type, doc.Content,doc.ID)
doc.Author, strings.Replace(doc.Title, "'", "\\'", -1), doc.Type,
strings.Replace(doc.Content, "'", "\\'", -1),doc.ID)
_, e := db.GetMysqlClient().Query(sql)
if nil != e {
logs.Error(e.Error())