-1
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
    })

How to assign john value to value_variable?

1 Answers1

2

Since Go is lexically scoped, you can assign value_variable inside the function you pass into 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
})
Community
  • 1
  • 1
tlehman
  • 5,125
  • 2
  • 33
  • 51