Esempio n. 1
0
/*
	Created specifically for RobotMP
*/
func (a *API) WriteTexts(w io.Writer, p PersonID) (err error) {
	bytes, err := a.get(
		"getHansard",
		url.Values{
			"person": {
				fmt.Sprint(p),
			},
			"num": {
				"10000",
			},
		},
	)

	if err != nil {
		return
	}

	var marshalled JsonHansard
	err = json.Unmarshal(bytes, &marshalled)
	if err != nil {
		return
	}
	for _, v := range marshalled.Rows {
		_, err := w.Write(sanitiseTexts(v.Body))
		if err != nil {
			return errors.Extend(err)
		}
	}
	return
}
Esempio n. 2
0
func Tdb(t *testing.T, lvl *level.Level) {
	path, err := osext.ExecutableFolder()
	if err != nil {
		panic(err)
	}
	db := &level.Database{
		Cache: lvl.NewCache(500 * level.Megabyte),
		Options: lvl.NewOptions().SetCreateIfMissing(
			true,
		),
	}
	err = lvl.OpenDatabase(db, path+"/leveldb/")
	if err != nil {
		t.Fatal("Error whilst loading DB: ", errors.Extend(err))
	}

	writeAtom := lvl.NewAtom().Put(
		keyone,
		valueone,
	).Put(
		keytwo,
		valuetwo,
	)

	err = db.Commit(
		writeAtom,
	)

	if err != nil {
		t.Fatal("Error performing atomic DB write: ", errors.Extend(err))
	}

	t.Log("Atom written: ", writeAtom)

	v, err := db.Get(
		keyone,
	)
	if err != nil {
		t.Fatal("Error retrieving key one: ", errors.Extend(err))
	}

	t.Log("Retrieved value: ", string(v))

	if !bytes.Equal(v, valueone) {
		t.Fatal("Values stored and retrived are not the same!")
	}

	v, err = db.Get(
		keytwo,
	)

	if err != nil {
		t.Fatal("Error retrieving key two: ", errors.Extend(err))
	}

	if !bytes.Equal(v, valuetwo) {
		t.Fatal("Values stored and retrived are not the same!")
	}

	//Delete the values from the DB.

	err = db.Commit(
		lvl.NewAtom().Delete(
			keyone,
		).Delete(
			keytwo,
		),
	)

	if err != nil {
		t.Fatal("Could not delete added keys: ", err)
	}

}