本文整理匯總了Golang中github.com/gin-gonic/gin.Context.Last方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Last方法的具體用法?Golang Context.Last怎麽用?Golang Context.Last使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Context
的用法示例。
在下文中一共展示了Context.Last方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: whereAmI
func whereAmI(c *gin.Context) {
var jsonData whereAmIJson
if c.BindJSON(&jsonData) == nil {
defer timeTrack(time.Now(), "getUniqueMacs")
db, err := bolt.Open(path.Join(RuntimeArgs.SourcePath, jsonData.Group+".db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()
locations := []string{}
db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
b := tx.Bucket([]byte("fingerprints-track"))
c := b.Cursor()
for k, v := c.Last(); k != nil; k, v = c.Prev() {
v2 := loadFingerprint(v)
if v2.Username == jsonData.User {
locations = append(locations, v2.Location)
}
if len(locations) > 2 {
break
}
}
return nil
})
// jsonLocations, _ := json.Marshal(locations)
message := "Found user"
if len(locations) == 0 {
message = "No locations found."
}
c.JSON(http.StatusOK, gin.H{"success": true, "message": message, "group": jsonData.Group, "user": jsonData.User, "locations": locations})
} else {
c.JSON(http.StatusOK, gin.H{"message": "Could not bind JSON - did you not send it as a JSON?", "success": false})
}
}
示例2: deleteLocations
func deleteLocations(c *gin.Context) {
group := strings.ToLower(c.DefaultQuery("group", "noneasdf"))
locationsQuery := strings.ToLower(c.DefaultQuery("names", "none"))
if group != "noneasdf" && locationsQuery != "none" {
locations := strings.Split(strings.ToLower(locationsQuery), ",")
db, err := bolt.Open(path.Join(RuntimeArgs.SourcePath, group+".db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
numChanges := 0
db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("fingerprints"))
if b != nil {
c := b.Cursor()
for k, v := c.Last(); k != nil; k, v = c.Prev() {
v2 := loadFingerprint(v)
for _, location := range locations {
if v2.Location == location {
b.Delete(k)
numChanges++
break
}
}
}
}
return nil
})
db.Close()
optimizePriorsThreaded(strings.ToLower(group))
c.JSON(http.StatusOK, gin.H{"message": "Deleted " + strconv.Itoa(numChanges) + " locations", "success": true})
} else {
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Need to provide group and location list. DELETE /locations?group=X&names=Y,Z,W"})
}
}