本文整理汇总了Golang中net/http.Request.ReplaceAllStringFunc方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.ReplaceAllStringFunc方法的具体用法?Golang Request.ReplaceAllStringFunc怎么用?Golang Request.ReplaceAllStringFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Request
的用法示例。
在下文中一共展示了Request.ReplaceAllStringFunc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: campaign
func campaign(w http.ResponseWriter, r *http.Request) {
var err error
var js []byte
var data Data
data = Data{}
if err = r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
switch r.Form["cmd"][0] {
case "get-data":
data.Id = r.Form["recid"][0]
dataId, err := strconv.ParseInt(data.Id, 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if auth.Right("get-campaign") && auth.CampaignRight(dataId) {
var start, end mysql.NullTime
err = models.Db.QueryRow("SELECT `name`,`profile_id`,`subject`,`sender_id`,`start_time`,`end_time`,`send_unsubscribe`,`body`,`accepted` FROM campaign WHERE id=?", data.Id).Scan(
&data.Name,
&data.ProfileId,
&data.Subject,
&data.SenderId,
&start,
&end,
&data.SendUnsubscribe,
&data.Template,
&data.Accepted,
)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
data.StartDate = start.Time.Unix()
data.EndDate = end.Time.Unix()
js, err = json.Marshal(data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
} else {
js = []byte(`{"status": "error", "message": "Forbidden get campaign"}`)
}
case "save-data":
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(&data)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
dataId, err := strconv.ParseInt(data.Id, 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if auth.Right("save-campaign") && auth.CampaignRight(dataId) {
start := time.Unix(data.StartDate, 0).Format(time.RFC3339)
end := time.Unix(data.EndDate, 0).Format(time.RFC3339)
// fix visual editor replace &
r := regexp.MustCompile(`(href|src)=["'](.*?)["']`)
data.Template = r.ReplaceAllStringFunc(data.Template, func(str string) string {
return strings.Replace(str, "&", "&", -1)
})
_, err := models.Db.Exec("UPDATE campaign SET `name`=?,`profile_id`=?,`subject`=?,`sender_id`=?,`start_time`=?,`end_time`=?,`send_unsubscribe`=?,`body`=? WHERE id=?",
data.Name,
data.ProfileId,
data.Subject,
data.SenderId,
start,
end,
data.SendUnsubscribe,
data.Template,
data.Id,
)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
js, err = json.Marshal(data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
} else {
js = []byte(`{"status": "error", "message": "Forbidden save campaign"}`)
}
case "accept":
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(&data)
if err != nil {
//.........这里部分代码省略.........