struct结构以下:git
package models import ( "github.com/robfig/revel" ) type Post struct { id int title string }
我在另外一个包里面使用github
package controllers import ( "blog/app/models" "fmt" "github.com/coopernurse/gorp" "github.com/robfig/revel" ) type Application struct { *revel.Controller Txn *gorp.Transaction } func (c Application) Index() revel.Result { post := &models.Post{1, "title"} fmt.Println(post) return c.Render() }
会出现以下错误:app
implicit assignment of unexported field
缘由是,struct定义的属性是小写开头的,不是public的,这样是不能跨包调用的!oop
正确的写法应该是post
type Post struct { Id int Title string }
属性大写blog