类使用:实现一个people中有一个sayhi的方法调用功能,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
type
People
struct
{
//..
}
func
(p *People) SayHi() {
fmt.Println(
"************************* say hi !!"
)
}
func
(this *LoginController) Get() {
p := new(People)
p.SayHi()
this.TplName =
"login.html"
}
|
接口使用:实现上面功能,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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"
}
|
本文转自王磊的博客博客园博客,原文链接:http://www.cnblogs.com/vipstone/p/5430667.html,如需转载请自行联系原作者