其他分享
首页 > 其他分享> > [Go] Method

[Go] Method

作者:互联网

// User
type User struct {
	ID        int
	FirstName string
}

// Method
func (u *User) describe() string {
	desc := fmt.Sprintf("Name %s", u.FirstName)
	return desc
}

// Order:
// 0 1 2 defer panic: NOT 2
func main() {
	user := User{FirstName: "JK", ID: 1}
	fmt.Println(user.describe())
}

describe() is a prop method on User struct

标签:string,FirstName,describe,User,Go,Method,struct
来源: https://www.cnblogs.com/Answer1215/p/16660304.html