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


Golang Request.Intn方法代码示例

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


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

示例1: BoardGetMove

func (ttt *TicTacToeApi) BoardGetMove(r *http.Request,
	req *BoardMsg, resp *BoardMsg) error {

	const boardLen = 9
	if len(req.State) != boardLen {
		return fmt.Errorf("Bad Request: Invalid board: %q", req.State)
	}
	runes := []rune(req.State)
	freeIndices := make([]int, 0)
	for pos, r := range runes {
		if r != 'O' && r != 'X' && r != '-' {
			return fmt.Errorf("Bad Request: Invalid rune: %q", r)
		}
		if r == '-' {
			freeIndices = append(freeIndices, pos)
		}
	}
	freeIdxLen := len(freeIndices)
	if freeIdxLen > 0 {
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		randomIdx := r.Intn(freeIdxLen)
		runes[randomIdx] = 'O'
		resp.State = string(runes)
	} else {
		return fmt.Errorf("Bad Request: This board is full: %q", req.State)
	}
	return nil
}
开发者ID:philips,项目名称:go-endpoints,代码行数:28,代码来源:api.go

示例2: Rock

func Rock(w http.ResponseWriter, r *http.Request) {
	w.Header().Add("Content Type", "text/html")
	tmpl, err := template.New("RPSLS").Parse(doc)
	if err == nil {
		var p1, p2 int
		var winner string
		r := rand.New(rand.NewSource(time.Now().UTC().UnixNano())) // makes a rand instance
		p1 = 3
		p2 = r.Intn(5) + 1
		// Judge
		result, death := judge(p1, p2, true)
		// Print
		switch result {
		case -1:
			winner = "Computer wins"
		case 0:
			winner = "Tie"
		case 1, 2, 3, 4:
			winner = "You win!"
		}
		choice := Choice{patterns[p1], patterns[p2], death, winner}
		tmpl.Execute(w, choice)
		//time.Sleep(3000 * time.Millisecond)
		//http.Redirect(w, r, "https://github.com", 301)
	}
}
开发者ID:ThyLeader,项目名称:RPSLS,代码行数:26,代码来源:app.go

示例3: TmkStatisticsDetailAction


//.........这里部分代码省略.........
	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	sql += " limit ?,?"

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	lessgo.Log.Debug(sql)

	rows, err = db.Query(sql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		model.Id = fmt.Sprint(r.Intn(1000))
		model.Props = []*lessgo.Prop{}

		fillObjects := []interface{}{}

		for i := 0; i < 11; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")
}
开发者ID:hjqhezgh,项目名称:wooyou-admin,代码行数:101,代码来源:tmkStatisticsAction.go

示例4: ConsultantPhoneListAction


//.........这里部分代码省略.........

	lessgo.Log.Debug(countSql)

	db := lessgo.GetMySQL()
	defer db.Close()

	rows, err := db.Query(countSql, params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	totalNum := 0

	if rows.Next() {
		err := rows.Scan(&totalNum)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}
	}

	totalPage := int(math.Ceil(float64(totalNum) / float64(pageSize)))

	currPageNo := pageNo

	if currPageNo > totalPage {
		currPageNo = totalPage
	}

	lessgo.Log.Debug(sql + " limit ?,?")

	params = append(params, (currPageNo-1)*pageSize)
	params = append(params, pageSize)

	rows, err = db.Query(sql+" limit ?,?", params...)

	if err != nil {
		lessgo.Log.Warn(err.Error())
		m["success"] = false
		m["code"] = 100
		m["msg"] = "系统发生错误,请联系IT部门"
		commonlib.OutputJson(w, m, " ")
		return
	}

	objects := []interface{}{}

	for rows.Next() {

		model := new(lessgo.Model)
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		model.Id = fmt.Sprint(r.Intn(1000))
		model.Props = []*lessgo.Prop{}

		fillObjects := []interface{}{}

		for i := 0; i < 7; i++ {
			prop := new(lessgo.Prop)
			prop.Name = fmt.Sprint(i)
			prop.Value = ""
			fillObjects = append(fillObjects, &prop.Value)
			model.Props = append(model.Props, prop)
		}

		err = commonlib.PutRecord(rows, fillObjects...)

		if err != nil {
			lessgo.Log.Warn(err.Error())
			m["success"] = false
			m["code"] = 100
			m["msg"] = "系统发生错误,请联系IT部门"
			commonlib.OutputJson(w, m, " ")
			return
		}

		objects = append(objects, model)
	}

	pageData := commonlib.BulidTraditionPage(currPageNo, pageSize, totalNum, objects)

	m["PageData"] = pageData
	m["DataLength"] = len(pageData.Datas) - 1
	if len(pageData.Datas) > 0 {
		m["FieldLength"] = len(pageData.Datas[0].(*lessgo.Model).Props) - 1
	}

	commonlib.RenderTemplate(w, r, "entity_page.json", m, template.FuncMap{"getPropValue": lessgo.GetPropValue, "compareInt": lessgo.CompareInt, "dealJsonString": lessgo.DealJsonString}, "../lessgo/template/entity_page.json")

}
开发者ID:hjqhezgh,项目名称:wooyou-admin,代码行数:101,代码来源:consultantPhoneListAction.go

示例5: pay

func pay(w http.ResponseWriter, r *http.Request) {
	if strings.ToUpper(r.Method) == "GET" {
		http.NotFound(w, r)
	} else if strings.ToUpper(r.Method) == "POST" {
		var chargeParams pingpp.ChargeParams
		w.Header().Set("Access-Control-Allow-Origin", "*")
		w.Header().Set("Content-Type", "application/json")
		defer r.Body.Close()
		buf := new(bytes.Buffer)
		buf.ReadFrom(r.Body)

		json.Unmarshal(buf.Bytes(), &chargeParams)
		r := rand.New(rand.NewSource(time.Now().UnixNano()))
		orderno := r.Intn(999999999999999)
		extra := make(map[string]interface{})
		switch strings.ToLower(chargeParams.Channel) {
		case "upacp_wap":
			extra["result_url"] = "http://www.yourdomain.com/result"
		case "alipay_wap":
			extra["cancel_url"] = "http://www.yourdomain.com/cancel"
			extra["success_url"] = "http://www.yourdomain.com/success"
		case "bfb_wap":
			extra["result_url"] = "http://www.yourdomain.com/result"
			extra["bfb_login"] = false
		case "yeepay_wap":
			extra["product_category"] = "1"
			extra["identity_id"] = "your_identity_id"
			extra["identity_type"] = 1
			extra["terminal_type"] = 1
			extra["terminal_id"] = "1sdf"
			extra["user_ua"] = "1qwec"
			extra["result_url"] = "http://www.yourdomain.com/result"
		case "wx_pub":
			extra["open_id"] = "your_openid"
		case "jdpay_wap":
			extra["success_url"] = "http://www.yourdomain.com/success"
			extra["fail_url"] = "http://www.yourdomain.com/fail"
			extra["token"] = "your_token_from_jd"
		case "wx_pub_qr":
			extra["product_id"] = "your_productid"

		}

		pingpp.Key = "sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"

		params := &pingpp.ChargeParams{
			Order_no:  strconv.Itoa(orderno),
			App:       pingpp.App{Id: "app_1Gqj58ynP0mHeX1q"},
			Amount:    chargeParams.Amount,
			Channel:   strings.ToLower(chargeParams.Channel),
			Currency:  "cny",
			Client_ip: "127.0.0.1",
			Subject:   "Your Subject",
			Body:      "Your Body",
			Extra:     extra,
		}

		//返回的第一个参数是 charge 对象,你需要将其转换成 json 给客户端,或者客户端接收后转换。
		ch, err := charge.New(params)

		if err != nil {
			errs, _ := json.Marshal(err)
			fmt.Fprint(w, string(errs))
		} else {
			chs, _ := json.Marshal(ch)
			fmt.Fprintln(w, string(chs))
		}

	}
}
开发者ID:jameswei,项目名称:pingpp-go,代码行数:70,代码来源:payDemoWithServer.go


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