類使用:實現一個people中有一個sayhi的方法呼叫功能,程式碼如下:
type People struct { //.. } func (p *People) SayHi() { fmt.Println("************************* say hi !!") } func (this *LoginController) Get() { p := new(People) p.SayHi() this.TplName = "login.html" }
介面使用:實現上面功能,程式碼如下:
type People struct { //.. } func (p *People) SayHi() { fmt.Println("************************* say hi !!") } type IPeople interface { SayHi() } func (this *LoginController) Get() { var p IPeople = new(People) p.SayHi() this.TplName = "login.html" }