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


Golang AuthenticatedRequest.FormValue方法代码示例

本文整理汇总了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
}
开发者ID:yinwer81,项目名称:haproxyconsole,代码行数:30,代码来源:main.go

示例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
}
开发者ID:yinwer81,项目名称:haproxyconsole,代码行数:44,代码来源:main.go

示例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
}
开发者ID:yinwer81,项目名称:haproxyconsole,代码行数:22,代码来源:main.go

示例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 {
//.........这里部分代码省略.........
开发者ID:yinwer81,项目名称:haproxyconsole,代码行数:101,代码来源:main.go

示例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)
	}
}
开发者ID:codingkoi,项目名称:oldbailey,代码行数:61,代码来源:view.go


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