将Go应用程序拆分为多个文件的方法(用于Go语言)

huangapple go评论70阅读模式
英文:

Splitting Go App Into Multiple Files for GoLang

问题

我正在使用GoLang版本的Go应用引擎来运行我的网站,主要是为了学习。

我现在想要编写多个Go服务端点来支持网站(主要是在管理员端)。我希望将它们分开,这样不会将所有内容都放在同一个文件中(为了维护方便),但是我似乎无法理清思路。

有没有办法将GoApp在GoLang中分成多个文件来提供和处理传入的请求?

理想情况下,这将是一个单一接口风格的包装文件,然后调用自己的文件中更复杂的方法。我考虑过按类型将.go文件放入单独的文件夹中,这样我的YAML文件就可以直接路由,但这似乎不太好。

英文:

I am using the GoLang version of the Go Application Engine to run my website. Mostly for learning.

I am at a point where I want to write multiple Go Service endpoints to support the site (mostly on the admin side). I would like to separate these so that not everything is in the same file (for maintenance sake), but cannot seem to get my head around this.

Is there a way to separate a GoApp in GoLang into multiple files to serve up and handle the incoming requests?

Ideally this would be a single interface style wrapper file that then calls into the more complex methods that are in their own files. I did think about putting the .go files by type into separate folders so that my YAML file could just route, but that does not seem as nice.

答案1

得分: 2

总结一下,简单来说,当你执行go build时,Go会自动编译同一文件夹中的.go文件。

文档链接:http://golang.org/doc/code.html

英文:

To summarize, in the simplest sense, Go automatically compiles .go files in the same folder when you execute go build.

Documentation: http://golang.org/doc/code.html

huangapple
  • 本文由 发表于 2014年12月3日 10:37:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/27262721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定