package main import ( "fmt" "strconv" "strings" "github.com/boltdb/bolt" ) func getAllLevelUpChannelXp(user string) map[string]int { openDatabase() ret := make(map[string]int) // First, get a list of all levelup stats db.Update(func(tx *bolt.Tx) error { var b, uB, uSB *bolt.Bucket var err error b = tx.Bucket([]byte("users")) if b == nil { return fmt.Errorf("Unable to open 'users' bucket") } if uB = b.Bucket([]byte(user)); uB != nil { if uSB = uB.Bucket([]byte("stats")); uSB != nil { return uSB.ForEach(func(k, v []byte) error { if strings.HasPrefix(string(k), "levelup-") { mapKey := strings.Replace(string(k), "levelup-", "", -1) if mapKey != "xp" { ret[mapKey], _ = strconv.Atoi(string(v)) } } return nil }) } } return err }) closeDatabase() return ret } func getAllNonLevelUpStats(user string) map[string]int { openDatabase() ret := make(map[string]int) // First, get a list of all levelup stats db.Update(func(tx *bolt.Tx) error { var b, uB, uSB *bolt.Bucket var err error b = tx.Bucket([]byte("users")) if b == nil { return fmt.Errorf("Unable to open 'users' bucket") } if uB = b.Bucket([]byte(user)); uB != nil { if uSB = uB.Bucket([]byte("stats")); uSB != nil { return uSB.ForEach(func(k, v []byte) error { if !strings.HasPrefix(string(k), "levelup-") { ret[string(k)], _ = strconv.Atoi(string(v)) } return nil }) } } return err }) closeDatabase() return ret }