Example #1
0
func setupDb(filepath string) {
	conn, err := sqlite.Open(filepath)
	if err != nil {
		panic(err)
	}
	dbase := sqlite_db.New(conn)
	kDoer = sqlite_db.NewDoer(dbase)
	kStore = for_sqlite.New(dbase)
}
Example #2
0
func main() {
	flag.Parse()
	if fDb == "" || fName == "" || fPassword == "" {
		fmt.Println("Need to specify -db, -name, and -password flag.")
		flag.Usage()
		return
	}
	conn, err := sqlite.Open(fDb)
	if err != nil {
		fmt.Printf("Unable to open database - %s\n", fDb)
		return
	}
	dbase := sqlite_db.New(conn)
	defer dbase.Close()
	store := for_sqlite.New(dbase)
	doer := sqlite_db.NewDoer(dbase)
	var user vsafe.User
	if err = store.UserByName(nil, fName, &user); err != nil {
		fmt.Printf("Error retrieving user - %v\n", err)
		return
	}
	var key *vsafe.Key
	if key, err = user.VerifyPassword(fPassword); err != nil {
		fmt.Printf("Error verifying user password - %v\n", err)
		return
	}
	decoder := json.NewDecoder(os.Stdin)
	var entryList []*jsonEntry
	if err = decoder.Decode(&entryList); err != nil {
		fmt.Printf("Error decoding json - %v\n", err)
		return
	}
	err = doer.Do(func(t db.Transaction) error {
		return doImport(t, store, entryList, key)
	})
	if err != nil {
		fmt.Printf("Import failed - %v\n", err)
	}
}