31 lines
622 B
Go
31 lines
622 B
Go
package database
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
func (db *Database) CheckPing(roleID string) int {
|
|
roleIDByte := []byte(roleID)
|
|
var idx int
|
|
_ = db.db.View(func(tx *bbolt.Tx) error {
|
|
num := tx.Bucket(firedBucket).Get(roleIDByte)
|
|
if num != nil {
|
|
if i, err := strconv.Atoi(string(num)); err == nil {
|
|
idx = i
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
return idx
|
|
}
|
|
|
|
func (db *Database) IncrementPing(roleID string) error {
|
|
roleIDByte := []byte(roleID)
|
|
return db.db.Update(func(tx *bbolt.Tx) error {
|
|
idx := db.CheckPing(roleID)
|
|
return tx.Bucket(firedBucket).Put(roleIDByte, []byte(strconv.Itoa(idx+1)))
|
|
})
|
|
}
|