2019独角兽企业重金招聘Python工程师标准>>>
src/test_interface.git/main.go
复制代码
1
2
3
4
5
6
7
8
package main import ( task "test_interface.git/task" ) func main() { do := task.NewInter(task.NewTask()) do.OnInit() }
src/test_interface.git/task/print.go
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
package task import ( "fmt" ) type Stve struct { } func NewTask() Inter { return &Stve{} } func (self *Stve) OnInit() { fmt.Println("Hello wrold") }
src/test_interface.git/task/interface.go
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package task import () type Inter interface { OnInit() } type App struct { app Inter } func NewInter(tmp Inter) *App { app1 := new(App) app1.app = tmp return app1 } func (self *App) OnInit() { self.app.OnInit() }
编译
go run main.go
执行结果:
复制代码
1
Hello wrold
转载于:https://my.oschina.net/ifraincoat/blog/517394
最后
以上就是默默热狗最近收集整理的关于golang 项目多文件编程示例的全部内容,更多相关golang内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复