Go 为结构体(struct)定义方法(method)

Submitted by Lizhe on Tue, 09/12/2017 - 18:32

 

package main

import (
    "fmt"
)

func main() {
    p := person{"lz", 30}
    p.Run();
}

type person struct {
    name string
    age  int
}

func (p person) Run() {
    fmt.Println("running",p.name)
}