package main import ( "fmt" ) const ( URL = "http://www.163.com" UID = "admin" TOKEN = "123456" ) type Ren struct { Phone string } type Student struct { Ren Name string Age int } type Teacher struct { Ren Name string Age int } func main() { a := Student{ Ren: Ren{Phone: "18532105052"}, Name: "test1", Age: 12, } b := Student{ Ren: Ren{Phone: "18582105055"}, Name: "kkk2", Age: 13, } fmt.Println(a, b) }
结构定义方法
type Teacher struct { Name string Age int } func main() { c := Teacher{} c.Say() } func (t Teacher) Say() { fmt.Println("say test test!") }
你好世界!