//定义结构体
type Dog struct {
ID int
Name string
Age int
}
//结构体方法
func (d *Dog) Run() {
fmt.Println(d.ID)
}
func main() {
var dog Dog
//var声明方式
dog.ID = 3
dog.Name = "struct"
dog.Age = 8
dog.Run()
}
后端开发
//定义结构体
type Dog struct {
ID int
Name string
Age int
}
//结构体方法
func (d *Dog) Run() {
fmt.Println(d.ID)
}
func main() {
var dog Dog
//var声明方式
dog.ID = 3
dog.Name = "struct"
dog.Age = 8
dog.Run()
}