Closed hanjiangjiaolong closed 4 years ago
var bucket
is only valid inside your Bolt().Update
func.
https://godoc.org/github.com/etcd-io/bbolt#Tx.Bucket
You can't reference it outside of that transaction.
but,i want get data,What i need to do
You don't need to create the buckets manually.
Just insert your model:
store, err := bolthold.Open(filename, 0666, nil)
if err != nil {
//handle error
}
err = store.Insert("king", &modeluserModel{
UserName: "king",
Password: "2959802013_",
})
dwedw := &model.UserModel{}
_ = store.Get("king", dwedw)
fmt.Println(dwedw)
When I have a default bucket, when I want to have a second bucket, should I innovate to create a store instance?
I'm not exactly following what you mean, but if you want to manually create and manage buckets, then I wouldn't suggest using Bolthold. Bolthold creates and manages it's own buckets based on the name of the type.
I have two types of data with different data structures, how to put them in the default bucket of Bolthold
Bolthold automatically creates a bucket for each type you put in. Use a new type and you get a new bucket.
If you really need to store two different types in the same bucket you can use an anonymous struct and combine the two.
struct {
Type1
Type2
}
This seems to be a good solution
his error occurs when fetching data from a specific bucket