本文整理汇总了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)
}
示例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
}
}
示例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("")
}
示例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("")
}
示例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)
}
示例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{}})
}
示例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)
}
示例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("")
}
示例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("")
}