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