本文整理汇总了Golang中github.com/coocood/jas.Context.FindInt方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.FindInt方法的具体用法?Golang Context.FindInt怎么用?Golang Context.FindInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coocood/jas.Context
的用法示例。
在下文中一共展示了Context.FindInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostNode
// PostNode creates a *Node from the submitted form and queues it for
// addition.
func (*Api) PostNode(ctx *jas.Context) {
if Db.ReadOnly {
// If the database is readonly, set that as the error and
// return.
ctx.Error = ReadOnlyError
return
}
// Initialize the node and retrieve fields.
node := new(Node)
ip := IP(net.ParseIP(ctx.RequireString("address")))
if ip == nil {
// If the address is invalid, return that error.
ctx.Error = jas.NewRequestError("addressInvalid")
return
}
node.Addr = ip
node.Latitude = ctx.RequireFloat("latitude")
node.Longitude = ctx.RequireFloat("longitude")
node.OwnerName = ctx.RequireString("name")
node.OwnerEmail = ctx.RequireString("email")
status, _ := ctx.FindInt("status")
node.Status = int(status)
// TODO(DuoNoxSol): Authenticate/limit node registration.
err := Db.AddNode(node)
if err != nil {
// If there was an error, log it and report the failure.
ctx.Error = jas.NewInternalError(err)
l.Err(err)
return
}
ctx.Data = "successful"
l.Infof("Node %q registered\n", ip)
}
示例2: RequireToken
// RequireToken uses the finder to retrieve a value named "token", and
// panics with "tokenInvalid" if there is either no such value, or it
// is invalid or expired.
func RequireToken(ctx *jas.Context) {
tokeni, err := ctx.FindInt("token")
if err != nil || !CheckToken(ctx.RemoteAddr, uint32(tokeni)) {
panic(jas.NewRequestError("tokenInvalid"))
}
}