本文介绍了从其他包导入的结构未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我讨厌的问题.我的models/model.go
Here is my noobish problem. I have this struct in my models/model.go
package models import ( "time" "gopkg.in/mgo.v2/bson" ) type Horse struct { Id bson.ObjectId `bson:"_id,omitempty"` Title string Description string CreatedOn time.Time Creator string Visits int Score int }在我的controllers/crud.go中,我正在尝试使用Horse结构
And in my controllers/crud.go I'm trying to use Horse struct
package controllers import ( "html/template" "log" "net/http" "horseapp/models" ) [...] var horseStore = make(map[string]Horse) //This raises undefined error但是当我go install horseapp时我得到了undefined: Horse.
这是怎么了?如何解决?
What is wrong here and how to fix it?
推荐答案使用
var horseStore = make(map[string]models.Horse)从另一个包访问标识符时,必须始终在包名前加上一个包名和一个点:package.Identifier
When accessing an identifier from another package you will always have to prefix it with the packages name and a dot: package.Identifier
更多推荐
从其他包导入的结构未定义
发布评论