我是靠谱客的博主 默默热狗,这篇文章主要介绍golang 项目多文件编程示例,现在分享给大家,希望可以做个参考。

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

src/test_interface.git/main.go

package main
import (
    task "test_interface.git/task"
)
func main() {
    do := task.NewInter(task.NewTask())
    do.OnInit()
}

src/test_interface.git/task/print.go

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

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


执行结果: 

Hello wrold


转载于:https://my.oschina.net/ifraincoat/blog/517394

最后

以上就是默默热狗最近收集整理的关于golang 项目多文件编程示例的全部内容,更多相关golang内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部