我目前正在使用 BoltDB 开发 Go 微服务。如何解决 golang 中的“未解决的引用错误”?
我有以下围棋代码:
// Start seeding accounts
//Funtion Seed Gives me error as the functions which i passed in Seed Functions are not defined even i defined.
func (bc *BoltClient) Seed() {
initializeBucket() // <-- this line gives error as it's undefined even i defined.
seedAccounts() // <-- this line gives error as it's undefined even i defined.
}
// Creates an "AccountBucket" in our BoltDB. It will overwrite any existing bucket of the same name.
func (bc *BoltClient) initializeBucket() {
bc.boltDB.Update(func(tx *bolt.Tx) error {
_, err := tx.CreateBucket([]byte("AccountBucket"))
if err != nil {
return fmt.Errorf("create bucket failed: %s", err)
}
return nil
})
}
func (bc *BoltClient) seedAccounts() {
total := 100
for i := 0; i < total; i++ {
//generating key larger than 10000
key := strconv.Itoa(10000 + i)
//Creating instance of account structure
acc := model.Account{
Id:key,
Name:"Person_" + strconv.Itoa(i),
}
//Serializing structure of JSON
jsonBytes, _ := json.Marshal(acc)
bc.boltDB.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("AccountBucket"))
err := b.Put([]byte(key), jsonBytes)
return err
})
}
fmt.Printf("Seeded %v fake accounts...\n", total)
}
当我执行代码时,我收到以下错误:
# _/home/dev46/dev46/code/go_projects/src/callistaenterprise_/goblog/accountservice/dbclient
dbclient/boltclient.go:32:2: undefined: initializeBucket
dbclient/boltclient.go:33:2: undefined: seedAccounts
我究竟做错了什么?