Beispiel #1
0
func updateDatabase(db *bolt.DB, version string) error {

	items, err := godragon.StaticItems(version)
	if err != nil {
		return err
	}
	var buff bytes.Buffer

	db.Update(func(tx *bolt.Tx) error {
		_, err := tx.CreateBucketIfNotExists([]byte("items"))
		return err
	})

	for i := range items {
		db.Update(func(tx *bolt.Tx) error {
			b := tx.Bucket([]byte("items"))

			enc := gob.NewEncoder(&buff)
			enc.Encode(items[i])
			err := b.Put([]byte(items[i].Name), buff.Bytes())
			buff.Reset()
			return err
		})
	}
	return nil
}
Beispiel #2
0
func main() {
	items, err := godragon.StaticItems("5.24.2")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	session, err := mgo.Dial("192.168.99.100")
	if err != nil {
		panic(err)
		os.Exit(1)
	}
	defer session.Close()

	for _, v := range items {
		c := session.DB("lol").C("items")

		err = c.Insert(v)
		if err != nil {
			log.Fatal(err)
		}
	}
}