类使用:实现一个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"
}
如果本文对你有所帮助,请打赏——1元就足够感动我:)
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
关注公众号:
作者: 王磊
出处: http://vipstone.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,请标明出处。