本文整理匯總了Golang中github.com/abbot/go-http-auth.AuthenticatedRequest.FormValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang AuthenticatedRequest.FormValue方法的具體用法?Golang AuthenticatedRequest.FormValue怎麽用?Golang AuthenticatedRequest.FormValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/abbot/go-http-auth.AuthenticatedRequest
的用法示例。
在下文中一共展示了AuthenticatedRequest.FormValue方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: editTask
// 編輯任務
func editTask(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
success := "true"
msg := "更新成功!"
servers := r.FormValue("servers")
backupServers := r.FormValue("backup_servers")
comment := r.FormValue("comment")
logornot := r.FormValue("logornot")
id := r.FormValue("id")
now := time.Now().Format("2006-01-02 15:04:05")
logOrNot, _ := strconv.Atoi(logornot)
taskId, _ := strconv.Atoi(id)
err := db.UpdateTaskInfo(servers, backupServers, comment, logOrNot, now, taskId)
if err != nil {
logger.Println(err)
success = "false"
msg = "數據存儲操作出現問題!"
}
result := statusResult{
Success: success,
Msg: msg,
}
rt, err := json.Marshal(result)
if err != nil {
fmt.Println(err)
}
fmt.Fprintf(w, string(rt))
return
}
示例2: applyConf
// 應用新HAProxy配置文件
func applyConf(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
success := "true"
msg := "成功應用!"
target := r.FormValue("target")
rebuildHAProxyConf()
if target == "master" {
bytes, err := ioutil.ReadFile(appConf.NewHAProxyConfPath)
masterConf, err := os.OpenFile(appConf.MasterConf, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
defer masterConf.Close()
masterConf.Write(bytes)
cmd := appConf.MasterRestartScript
cmdToRun := exec.Command(cmd)
err = cmdToRun.Run()
if err != nil {
logger.Println(err)
success = "false"
msg = fmt.Sprintf("應用失敗!%s", err.Error())
}
} else {
var err error
if appConf.CopyMethod == 1 {
err = sshoperation.ScpHaproxyConf(appConf)
}
if appConf.CopyMethod == 2 {
err = sshoperation.ConfidentialScpHAProxyConf(appConf)
}
if err != nil {
success = "false"
msg = fmt.Sprintf("應用失敗!%s", err.Error())
}
}
result := statusResult{
Success: success,
Msg: msg,
}
rt, err := json.Marshal(result)
if err != nil {
fmt.Println(err)
}
fmt.Fprintf(w, string(rt))
return
}
示例3: delListenTask
// 刪除任務
func delListenTask(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
success := "true"
msg := "已成功刪除"
taskId := r.FormValue("taskid")
id, _ := strconv.Atoi(taskId)
result, err := db.DeleteTask(id)
if err != nil {
logger.Fatalln(err)
success = "false"
msg = "刪除數據出錯!"
}
rowsAffected, err := result.RowsAffected()
if rowsAffected != 1 {
success = "false"
msg = fmt.Sprintf("數據刪除有問題,刪除了%d條", rowsAffected)
}
rt, _ := json.Marshal(statusResult{Success: success, Msg: msg})
fmt.Fprintf(w, string(rt))
return
}
示例4: applyVPort
// 申請虛擬ip端口請求處理函數
func applyVPort(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
autoOrNot, _ := strconv.Atoi(r.FormValue("autoornot"))
business := -1
var port int
if autoOrNot == 1 && appConf.BusinessList != "" {
business, _ = strconv.Atoi(r.FormValue("business"))
}
if autoOrNot == 0 {
port, _ = strconv.Atoi(r.FormValue("port"))
}
servers := r.FormValue("servers")
backupServers := r.FormValue("backup_servers")
comment := strings.TrimSpace(r.FormValue("comment"))
logOrNot := r.FormValue("logornot")
rows, err := db.QueryVPort()
if err != nil {
logger.Println(err)
}
rowNum := len(rows)
vportToAssign := -1
dupOrNot := 0
noAvailablePort := false
// 若是指定端口方式,則判斷指定的端口是否在1000-99999範圍內
inPortRange := true
if autoOrNot == 0 && port < 1000 || port > 99999 {
inPortRange = false
}
if inPortRange == true {
/*
將1000到已分配的最大端口號之間所有未占用和已占用的端口映射到一個真假值數組
*/
var portSlots []bool
var assignedBiggest int
if rowNum > 0 {
assignedBiggest = rows[rowNum-1]
allowedSmallest := 1000
mayAssignedPortRange := assignedBiggest - allowedSmallest + 1
//fmt.Println(mayAssignedPortRange)
portSlots = make([]bool, mayAssignedPortRange)
/*
* 注意上一句make的用法-容量和長度都為mayAssignedPortRange,
* 並且所有bool類型元素都自動初始化為false,所以下麵的幾行初始化代碼不再需要。
*/
/*
fmt.Println(portSlots[0])
fmt.Println(portSlots[1])
fmt.Println(portSlots[mayAssignedPortRange-1])
for index := 0; index < mayAssignedPortRange; index++ {
portSlots[index] = false
}
*/
for index := 0; index < rowNum; index++ {
port := rows[index]
portSlots[port-1000] = true
}
}
// 自動分配端口
if autoOrNot == 1 {
// 未指定業務
if business == -1 {
/*
虛擬ip端口自動分配算法(不指定業務)
可分配端口範圍:10000 - 19999
*/
if rowNum == 0 {
vportToAssign = 10000
} else {
vportToAssign, noAvailablePort = autoAssignPort(10000, 19999, assignedBiggest, portSlots)
}
} else {
// 指定業務
var portRange string
businesses := strings.Split(appConf.BusinessList, ";")
for index, bToPortRange := range businesses {
if index == business {
thisBToPortRange := strings.Split(bToPortRange, ",")
if comment != "" {
comment += "<br />"
}
comment += "業務:" + thisBToPortRange[0]
portRange = thisBToPortRange[1]
break
}
}
firstAndLast := strings.Split(portRange, "-")
firstPort, _ := strconv.Atoi(firstAndLast[0])
lastPort, _ := strconv.Atoi(firstAndLast[1])
if rowNum == 0 {
vportToAssign = firstPort
} else {
vportToAssign, noAvailablePort = autoAssignPort(firstPort, lastPort, assignedBiggest, portSlots)
}
}
} else {
//.........這裏部分代碼省略.........
示例5: CaseHandler
func CaseHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
var err error
path := r.URL.Path
pattern, err := regexp.Compile("/case/([^/]*)")
if err != nil {
panic(err)
}
matches := pattern.FindStringSubmatch(path)
if len(matches) != 2 {
resourceNotFound(w, &r.Request)
return
}
id := matches[1]
switch r.Method {
case "GET":
baileyCase := record.FetchRecord(id)
if baileyCase == nil {
resourceNotFound(w, &r.Request)
return
}
responseBody := mustache.RenderFile("view/case.html", baileyCase)
w.Write([]byte(responseBody))
case "POST":
baileyCase := record.FetchRecord(id)
if baileyCase == nil {
resourceNotFound(w, &r.Request)
return
}
var jsonUpdate JsonUpdate
err = json.Unmarshal([]byte(r.FormValue("json")), &jsonUpdate)
if err != nil {
log.Println(err)
badRequest(w, &r.Request)
return
}
// this is really ugly code, and should be fixed asap
baileyCase.OfInterest = jsonUpdate.OfInterest
baileyCase.NotOfInterest = jsonUpdate.NotOfInterest
baileyCase.Clothing = jsonUpdate.Clothing
baileyCase.ClothingCount = jsonUpdate.ClothingCount
baileyCase.RawTextiles = jsonUpdate.RawTextiles
baileyCase.RawTextilesCount = jsonUpdate.RawTextilesCount
baileyCase.OtherTextiles = jsonUpdate.OtherTextiles
baileyCase.Accessories = jsonUpdate.Accessories
baileyCase.AccessoriesCount = jsonUpdate.AccessoriesCount
baileyCase.HouseholdLinen = jsonUpdate.HouseholdLinen
baileyCase.HouseholdLinenCount = jsonUpdate.HouseholdLinenCount
baileyCase.Other = jsonUpdate.Other
baileyCase.OtherCount = jsonUpdate.OtherCount
baileyCase.OtherNotSpecified = jsonUpdate.OtherNotSpecified
baileyCase.Save()
successNoContent(w, &r.Request)
default:
methodNotAllowed(w, &r.Request)
}
}