类使用:实现一个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"
}

 

相关文章:

  • 2021-05-17
  • 2022-02-10
  • 2021-10-22
  • 2022-12-23
  • 2021-08-30
  • 1970-01-01
  • 2021-11-11
  • 2022-12-23
猜你喜欢
  • 2019-03-27
  • 2018-12-22
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案