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


Golang Request.FormValue方法代码示例

本文整理汇总了Golang中github.com/ant0ine/go-json-rest/rest.Request.FormValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.FormValue方法的具体用法?Golang Request.FormValue怎么用?Golang Request.FormValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ant0ine/go-json-rest/rest.Request的用法示例。


在下文中一共展示了Request.FormValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getDeviceList

func getDeviceList(w rest.ResponseWriter, r *rest.Request) {
	stats.QueryOnlineDevices()

	devInfoList := []devInfo{}
	r.ParseForm()
	dev_ids := r.FormValue("dev_ids")
	if dev_ids != "" {
		ids := strings.Split(dev_ids, ",")
		for _, id := range ids {
			if serverName, err := storage.Instance.CheckDevice(id); err == nil && serverName != "" {
				info := devInfo{
					Id: id,
				}
				devInfoList = append(devInfoList, info)
			}
		}
	} else {
		rest.Error(w, "Missing \"dev_ids\"", http.StatusBadRequest)
		return
	}

	resp := cloud.ApiResponse{}
	resp.ErrNo = cloud.ERR_NOERROR
	resp.Data = devInfoList
	w.WriteJson(resp)
}
开发者ID:houcy,项目名称:push,代码行数:26,代码来源:controlapi.go

示例2: get_object__decode_request

func get_object__decode_request(res rest.ResponseWriter, req *rest.Request) (string, string, map[string]bool, bool) {
	// get CONTENT-TYPE parameter
	contentType := req.PathParam("content-type")
	if len(contentType) == 0 {
		rest.Error(res, "Invalid content type", 400)
		return "", "", nil, true
	}

	// get ID parameter
	doc_id := req.PathParam("id")
	if len(doc_id) == 0 {
		rest.Error(res, "Invalid content ID", 400)
		return "", "", nil, true
	}

	// get PAYLOAD parameters
	flags := map[string]bool{
		"payload": true,
	}
	for flag_name, _ := range flags {
		if req.Form[flag_name] != nil {
			flag_str := req.FormValue(flag_name)
			flag, err := strconv.ParseBool(flag_str)
			if err != nil {
				rest.Error(res, "Invalid query "+flag_name+". "+err.Error(), 400)
				return "", "", nil, true
			}
			flags[flag_name] = flag
		}
	}

	return contentType, doc_id, flags, false
}
开发者ID:PipeGrep,项目名称:autocomplete-redis-golang-api,代码行数:33,代码来源:get_object.go

示例3: getDevice

func getDevice(w rest.ResponseWriter, r *rest.Request) {
	devId := r.PathParam("devid")

	r.ParseForm()
	token := r.FormValue("token")
	if token == "" {
		rest.Error(w, "Missing \"token\"", http.StatusBadRequest)
		return
	}

	if !checkAuthz(token, devId) {
		log.Warnf("Auth failed. token: %s, device_id: %s", token, devId)
		rest.Error(w, "Authorization failed", http.StatusForbidden)
		return
	}

	stats.QueryDeviceInfo()

	if serverName, err := storage.Instance.CheckDevice(devId); err == nil && serverName != "" {
		resp := cloud.ApiResponse{}
		resp.ErrNo = cloud.ERR_NOERROR
		resp.Data = devInfo{
			Id: devId,
		}
		w.WriteJson(resp)
	} else {
		rest.NotFound(w, r)
		return
	}
}
开发者ID:houcy,项目名称:push,代码行数:30,代码来源:controlapi.go

示例4: FileDelete

// POST /files/delete
func FileDelete(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	id, _ := strconv.ParseInt(r.FormValue("Id"), 10, 64)
	file := database.FindFile(id)

	// Delete from DB
	database.DeleteFile(file)
	w.WriteJson("")
}
开发者ID:CanarySolutions,项目名称:android_ota_manager,代码行数:10,代码来源:files.go

示例5: APIDialogIndex

// APIDialogIndex is used to get dialogs index
func (i *Impl) APIDialogIndex(w rest.ResponseWriter, r *rest.Request) {
	userID := r.PathParam("user_id")
	page, err := strconv.Atoi(r.FormValue("page"))
	offset := 0
	if err == nil {
		offset = (page - 1) * 10
	}

	dialogs := i.GetDialogs(userID, offset)
	w.WriteJson(&dialogs)
}
开发者ID:arrowcircle,项目名称:messenger,代码行数:12,代码来源:api.go

示例6: APIMessageIndex

// APIMessageIndex is used to show dialog messages
func (i *Impl) APIMessageIndex(w rest.ResponseWriter, r *rest.Request) {
	userID := r.PathParam("user_id")
	dialogID, _ := strconv.Atoi(r.PathParam("dialog_id"))
	page, err := strconv.Atoi(r.FormValue("page"))
	offset := 0
	if err == nil {
		offset = (page - 1) * 10
	}

	messages := i.IndexMessages(userID, dialogID, offset)

	w.WriteJson(&messages)
}
开发者ID:arrowcircle,项目名称:messenger,代码行数:14,代码来源:api.go

示例7: authKeyValue

func authKeyValue(req *rest.Request) (string, bool) {
	key := req.FormValue("api_key")
	if key != "" {
		return key, true
	}

	key = req.Header.Get("Authorization")
	if key == "" {
		return "", false
	} else {
		return key, true
	}
}
开发者ID:angdev,项目名称:chocolat,代码行数:13,代码来源:auth.go

示例8: getEmailContent

//获取与id对应的邮件内容
func (email *Email) getEmailContent(w rest.ResponseWriter, r *rest.Request) {
	log.Printf("get email content...")
	addr := r.FormValue("pop3Addr")
	//使用pop3Addr参数区分协议类型
	log.Printf("pop3 addr=%s\n", addr)

	if addr != "" {
		email.getEmailContentUsePop3(w, r)
	} else {
		email.getEmailContentUseIMAP(w, r)
	}

}
开发者ID:yuanlv,项目名称:learning-in-go,代码行数:14,代码来源:rest_email.go

示例9: ReleaseDelete

// POST /releases/delete
func ReleaseDelete(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	id, _ := strconv.ParseInt(r.FormValue("Id"), 10, 64)
	release := database.FindRelease(id)
	file := database.FindFile(release.FileId)

	// Delete from DB
	database.DeleteRelease(release)
	database.UnpublishFile(file)
	go database.RefreshBuilds()

	// http.Redirect(w, r, "/admin/releases", http.StatusFound)
	w.WriteJson("")
}
开发者ID:CanarySolutions,项目名称:android_ota_manager,代码行数:15,代码来源:releases.go

示例10: eventData

func eventData(req *rest.Request, out interface{}) error {
	encoded := req.FormValue("data")
	if encoded != "" {
		if err := decodeData(encoded, &out); err != nil {
			return err
		} else {
			return nil
		}
	}

	if err := req.DecodeJsonPayload(&out); err != nil {
		return err
	} else {
		return nil
	}
}
开发者ID:angdev,项目名称:chocolat,代码行数:16,代码来源:events.go

示例11: GetEmailListAndContent

/*
	GET /email 统一入口,通过参数区分具体的请求
 GET /email?pop3Addr=pop.163.com&pop3Port=22&user=myusername&pwd=mypasswords&afterId=***
 GET /email?pop3Addr=pop.163.com&pop3Port=22&user=myusername&pwd=mypasswords&id=***

 tes url
 http://localhost:8080/email?pop3Addr=pop.126.com&pop3Port=110&[email protected]&pwd=***&afterId=1
*/
func (email *Email) GetEmailListAndContent(w rest.ResponseWriter, r *rest.Request) {
	log.Printf("enter into get email list and content...")
	//检验参数是否完整

	getListArgs := r.FormValue("afterId")
	getContentArgs := r.FormValue("id")

	log.Printf("url query params: afterId=%s, id=%s", getListArgs, getContentArgs)

	if getListArgs != "" {
		email.getEmailList(w, r)
	} else if getContentArgs != "" {
		email.getEmailContent(w, r)
	}

	//回复错误信息

}
开发者ID:yuanlv,项目名称:learning-in-go,代码行数:26,代码来源:rest_email.go

示例12: getRouterList

func getRouterList(w rest.ResponseWriter, r *rest.Request) {
	type RouterInfo struct {
		Rid   string `json:"rid"`
		Rname string `json:"rname"`
	}

	type ResponseRouterList struct {
		Status int          `json:"status"`
		Descr  string       `json:"descr"`
		List   []RouterInfo `json:"list"`
	}

	resp := ResponseRouterList{}
	resp.Status = STATUS_OTHER_ERR
	r.ParseForm()

	uid := r.FormValue("uid")
	if uid == "" {
		resp.Status = STATUS_INVALID_PARAM
		resp.Descr = "missing 'uid'"
		w.WriteJson(resp)
		return
	}

	devices, err := devcenter.GetDevices(uid, devcenter.DEV_ROUTER)
	if err != nil {
		log.Errorf("GetDevices failed: %s", err.Error())
		resp.Descr = err.Error()
		w.WriteJson(resp)
		return
	}

	for _, dev := range devices {
		router := RouterInfo{
			Rid:   dev.Id,
			Rname: dev.Title,
		}
		resp.List = append(resp.List, router)
	}

	resp.Status = 0
	resp.Descr = "OK"
	w.WriteJson(resp)
}
开发者ID:houcy,项目名称:push,代码行数:44,代码来源:controlapi.go

示例13: getSysStats

func getSysStats(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	startDate := r.FormValue("start_date")
	endDate := r.FormValue("end_date")

	var (
		start time.Time
		end   time.Time
		err   error
	)
	if startDate == "" {
		start = time.Now()
	} else {
		if start, err = time.Parse("20060102", startDate); err != nil {
			rest.Error(w, "invalid date format", http.StatusBadRequest)
			return
		}
	}
	if endDate == "" {
		end = time.Now()
	} else {
		if end, err = time.Parse("20060102", endDate); err != nil {
			rest.Error(w, "invalid date format", http.StatusBadRequest)
			return
		}
	}
	if start.After(end) {
		rest.Error(w, "start date greater than end date", http.StatusBadRequest)
		return
	}

	resp := Response{
		ErrNo: 0,
	}
	resp.Data, err = storage.Instance.GetSysStats(start, end)
	if err != nil {
		rest.Error(w, "storage I/O failed", http.StatusInternalServerError)
		log.Warnf("GetSysStats failed: %s", err.Error())
		return
	}
	w.WriteJson(resp)
}
开发者ID:houcy,项目名称:push,代码行数:42,代码来源:pushapi.go

示例14: getEmailListUsePop3

func (email *Email) getEmailListUsePop3(w rest.ResponseWriter, r *rest.Request) ([]EmailHeader, error) {
	addr := r.FormValue("pop3Addr")
	port := r.FormValue("pop3Port")
	user := r.FormValue("user")
	pwd := r.FormValue("pwd")
	afterId := r.FormValue("afterId")

	address := addr + ":" + port
	log.Printf("pop3 addr=%s\n", address)

	client, err := email.getPop3EmailClient(address, user, pwd)
	if err != nil {
		return nil, err
	}

	defer func() {
		client.Quit()
		client.Close()
	}()

	var count int
	var size uint64

	if count, size, err = client.Stat(); err != nil {
		log.Printf("Error: %v\n", err)
		return nil, err
	}

	log.Printf("Count: %d, Size: %d\n", count, size)

	//获取指定afterid及以后的所有邮件列表
	headers := make([]EmailHeader, 0)
	id, _ := strconv.Atoi(afterId)
	for i := id; i <= count; i++ {
		log.Printf("=============")
		log.Printf("i=%d, count=%d\n", i, count)
		if _, size, err = client.List(i); err != nil {
			log.Printf("Error: %v\n", err)
			return nil, err
		}

		log.Printf("email Number: %d, Size: %d\n", i, size)

		header := EmailHeader{}
		header.Id = strconv.Itoa(i)

		headers = append(headers, header)
	}

	return headers, nil
}
开发者ID:yuanlv,项目名称:learning-in-go,代码行数:51,代码来源:rest_email.go

示例15: getEmailContentUsePop3

func (email *Email) getEmailContentUsePop3(w rest.ResponseWriter, r *rest.Request) {
	addr := r.FormValue("pop3Addr")
	port := r.FormValue("pop3Port")
	user := r.FormValue("user")
	pwd := r.FormValue("pwd")
	id := r.FormValue("id")

	address := addr + ":" + port
	client, err := email.getPop3EmailClient(address, user, pwd)
	if err != nil {
		errorInfo := ErrorInfo{Code: 403, Name: ""}
		resp := EmailJsonResponse{Success: false, Error: errorInfo}
		w.WriteJson(&resp)
	}

	defer func() {
		client.Quit()
		client.Close()
	}()

	var body string
	content := EmailContent{}
	i, _ := strconv.Atoi(id)
	if body, err = client.Retr(i); err != nil {
		log.Printf("Error: %v\n", err)
		errorInfo := ErrorInfo{Code: 403, Name: ""}
		resp := EmailJsonResponse{Success: false, Error: errorInfo}
		w.WriteJson(&resp)
		return
	}

	_, subject, senderAddr, err := parseContent(body)
	//skip parse error
	if err != nil {
		log.Printf("parse email body error")
		errorInfo := ErrorInfo{Code: 403, Name: ""}
		resp := EmailJsonResponse{Success: false, Error: errorInfo}
		w.WriteJson(&resp)
		return
	}

	content.SenderAddr = senderAddr
	content.SenderName = ""
	content.Subject = subject
	content.Content = body

	resp := EmailJsonResponse{Success: true, Data: content}
	w.WriteJson(&resp)
}
开发者ID:yuanlv,项目名称:learning-in-go,代码行数:49,代码来源:rest_email.go


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