内容简介:最近把我的ss项目做了一下结构调整,一顿重构后,输入go run main.go,编译报错function undefined。额,怎么回事明明把函数定义在main.go上面的文件中啊。之前也遇到过这个问题不过没用深究,下面我们来说说go main包那点事。golang main包推荐只有一个main.go文件,这样大家就能按照习惯的方式,如果main包下有多个go文件,应该使用
最近把我的ss项目做了一下结构调整,一顿重构后,输入go run main.go,编译报错function undefined。额,怎么回事明明把函数定义在main.go上面的文件中啊。之前也遇到过这个问题不过没用深究,下面我们来说说go main包那点事。
golang main包推荐只有一个main.go文件,这样大家就能按照习惯的方式, go run main.go 或 go build main.go
来运行编译项目。
如果main包下有多个 go 文件,应该使用 go run a.go b.go c.go 或 go run *.go
来运行,编译同理。
因为mian包里,使用go run main.go,编译器只会加载main.go这个文件,不会加载main包里的其他文件,只有非main包里的文件才会通过依赖去自动加载。所以你需要输入多个文件作为参数。
golang推荐项目结构:
.
├── .gitignore
├── README.md
├── main.go
└── src
├── pkg1
│ └── a.go
├── pkg2
│ └── b.go
└── pkg3
└── c.go
如果需要编译为多个程序,可以加入cmd文件夹:
.
├── .gitignore
├── README.md
├── cmd
│ ├── cmd1
│ │ └── main.go
│ └── cmd2
│ └── main.go
└── src
├── pkg1
│ └── a.go
├── pkg2
│ └── b.go
└── pkg3
└── c.go
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Security Testing Cookbook
Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99
Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!
JS 压缩/解压工具
在线压缩/解压 JS 代码
Markdown 在线编辑器
Markdown 在线编辑器