gpt4 book ai didi

Golang bolt 获取值

转载 作者:数据小太阳 更新时间:2023-10-29 03:41:29 24 4
gpt4 key购买 nike

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

如何给 value_variable 赋值?

最佳答案

因为 Go 是 lexically scoped ,您可以在传递给 View 的函数中分配 value_variable:

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

关于Golang bolt 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29105275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com