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


Golang Request.ParseForm方法代码示例

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


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

示例3: 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

示例4: 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

示例5: getAppStats

func getAppStats(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	appId := r.FormValue("appid")
	startDate := r.FormValue("start_date")
	endDate := r.FormValue("end_date")
	if appId == "" {
		rest.Error(w, "missing 'appid'", http.StatusBadRequest)
		return
	}

	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.GetAppStats(appId, start, end)
	if err != nil {
		rest.Error(w, "storage I/O failed", http.StatusInternalServerError)
		log.Warnf("GetAppStats failed: %s", err.Error())
		return
	}
	w.WriteJson(resp)
}
开发者ID:houcy,项目名称:push,代码行数:47,代码来源:pushapi.go

示例6: FileOpenHandler

/* API: This returns the file content of given file in project directory
> curl -i http://127.0.0.1:3000/api/files/open?t=
*/
func FileOpenHandler(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	target := r.Form.Get("target")

	if target == "" {
		rest.Error(w, "Missing target file.", http.StatusBadRequest)
		return
	}

	content, err := ioutil.ReadFile(projectDir + target)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.WriteJson(&Editable{target, fmt.Sprintf("%s", content), []string{}})
}
开发者ID:kotharthar,项目名称:webplug,代码行数:20,代码来源:server.go

示例7: 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

示例8: ReleaseUpdate

// POST /releases/update
func ReleaseUpdate(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()

	// Parse form and append to struct
	id, _ := strconv.ParseInt(r.FormValue("Id"), 10, 64)
	fileId, _ := strconv.ParseInt(r.FormValue("FileId"), 10, 64)
	release := database.FindRelease(id)
	file := database.FindFile(fileId)
	release.FileId = file.Id
	release.FileName = file.Name
	release.Channel = r.FormValue("Channel")
	release.Changelog = r.FormValue("Changelog")

	// Append to db
	database.UpdateRelease(release)

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

示例9: ReleaseCreate

// POST /releases/create
func ReleaseCreate(w rest.ResponseWriter, r *rest.Request) {
	r.ParseForm()
	fileId, _ := strconv.ParseInt(r.FormValue("FileId"), 10, 64)
	file := database.FindFile(fileId)

	// Generate release
	release := database.Release{
		Created:   time.Now().UnixNano(),
		Changelog: r.FormValue("Changelog"),
		Channel:   r.FormValue("Channel"),
		FileId:    file.Id,
		FileName:  file.Name,
	}

	database.CreateRelease(release)
	database.PublishFile(file)
	go database.RefreshBuilds()
	w.WriteJson("")
}
开发者ID:CanarySolutions,项目名称:android_ota_manager,代码行数:20,代码来源:releases.go


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