implicit assignment of unexported field
生活随笔
收集整理的這篇文章主要介紹了
implicit assignment of unexported field
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
struct結構如下:
package modelsimport ("github.com/robfig/revel" )type Post struct {id inttitle string }我在另一個包里面使用
package controllersimport ("blog/app/models""fmt""github.com/coopernurse/gorp""github.com/robfig/revel" )type Application struct {*revel.ControllerTxn *gorp.Transaction }func (c Application) Index() revel.Result {post := &models.Post{1, "title"}fmt.Println(post)return c.Render() }會出現(xiàn)如下錯誤:
implicit assignment of unexported field?
原因是,struct定義的屬性是小寫開頭的,不是public的,這樣是不能跨包調用的!
正確的寫法應該是
type Post struct {Id intTitle string }屬性大寫
轉載于:https://my.oschina.net/u/2362111/blog/748914
總結
以上是生活随笔為你收集整理的implicit assignment of unexported field的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sql注入攻击与防御第二版读书笔记二——
- 下一篇: des解密不完整,前面几位是乱码的解决办