修复sql语句单引号的问题
parent
4e2ff25d38
commit
0d27f524ed
|
@ -83,7 +83,14 @@ func initMysqlTLS(mysqlconf *config.MysqlConfig) *sql.DB {
|
||||||
return _db
|
return _db
|
||||||
}
|
}
|
||||||
func initMongoDb(conf *config.MongoConfig) *mgo.Session{
|
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)
|
log.Print("connect to url " + url)
|
||||||
logs.Debug("connect to url " + url)
|
logs.Debug("connect to url " + url)
|
||||||
|
|
||||||
|
@ -111,5 +118,4 @@ func InitMongoDb() {
|
||||||
log.Print("error mongo initial")
|
log.Print("error mongo initial")
|
||||||
os.Exit(25)
|
os.Exit(25)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
3
main.go
3
main.go
|
@ -44,7 +44,8 @@ func InitLogs() {
|
||||||
}
|
}
|
||||||
func CORSMiddleware(c *gin.Context) {
|
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-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-Max-Age", "86400")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Headers",
|
c.Writer.Header().Set("Access-Control-Allow-Headers",
|
||||||
"X-Requested-With," +
|
"X-Requested-With," +
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"background/db"
|
"background/db"
|
||||||
"background/logs"
|
"background/logs"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Doc struct {
|
type Doc struct {
|
||||||
|
@ -50,7 +51,8 @@ WHERE
|
||||||
|
|
||||||
func UpdateDoc(doc Doc) error{
|
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'; `,
|
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)
|
_, e := db.GetMysqlClient().Query(sql)
|
||||||
if nil != e {
|
if nil != e {
|
||||||
logs.Error(e.Error())
|
logs.Error(e.Error())
|
||||||
|
|
Loading…
Reference in New Issue