var value_variable
// Access data from within a read-only transactional block.
db.View(func(tx *bolt.Tx) error {
v := tx.Bucket([]byte("people")).Get([]byte("john"))
fmt.Printf("John's last name is %s.\n", v)
return nil
})
如何将john值赋给value_variable?
答案 0 :(得分:1)
由于Go为lexically scoped,您可以在传递给value_variable
的函数中指定View
:
var value_variable []byte
// Access data from within a read-only transactional block.
db.View(func(tx *bolt.Tx) error {
v := tx.Bucket([]byte("people")).Get([]byte("john"))
value_variable = v // <----- ASSIGN IT HERE
fmt.Printf("John's last name is %s.\n", v)
return nil
})