当前位置: 首页>>代码示例>>Golang>>正文


Golang Request.ReplaceAllStringFunc方法代码示例

本文整理汇总了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 {
//.........这里部分代码省略.........
开发者ID:Supme,项目名称:gonder,代码行数:101,代码来源:campaign.go


注:本文中的net/http.Request.ReplaceAllStringFunc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。