go chapter 8 - 初始化对象
http://blog.haohtml.com/archives/14239
struct定义的属性如果是小写开头的,那么该属性不是public的,不能跨包调用 (implicit assignment of unexported field)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | type Rect struct { x, y float64 width, height float64 } // 定义一个对象,以下四种等价。 rect1 := new(Rect) rect2 := &Rect{} rect3 := &Rect{0, 0, 100, 200} rect4 := &Rect{width:100, height:200} //=================================== package entities type Company struct { Id string Name string Phone string Address string } // 声明一个类型 r := entities.Company{Id: "001" , Name: "test name" , Phone: "test phone" , Address: "test address" } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步