<p>I am following <a href="https://thenewstack.io/make-a-restful-json-api-go/" rel="nofollow">this guide</a>. </p>
<p>So at my current working directory I have five files. handles.go, logger.go, routes.go routes.go and main.go. </p>
<p>My main.go looks like the following: </p>
<pre><code>package main
import (
"log"
"net/http"
)
func main() {
router := NewRouter()
log.Fatal(http.ListenAndServe(":8080", router))
}
</code></pre>
<p><code>NewRouter</code> is a function defined in <code>routes.go</code>. Several other functions are also being called among those <code>.go</code>. In the tutorial, I see no include/import statement for those <code>.go</code> files; My guess is there must be some parameters that's being passed in <code>go build</code> or <code>go run</code> that will incorporate all the files? if so what is it? </p>
<hr/>**评论:**<br/><br/>sxan: <pre><p>If all files are in the same directory, and they're all in package main, no imports are needed.</p></pre>juniorsysadmin1: <pre><p>it doesn't work when I do <code>go run main.go</code> it complain about the routerfunction that is defined in <code>routes.go</code>.</p></pre>TheMerovius: <pre><p>Use <code>go build</code> or <code>go run *.go</code>. run and build have very different behaviors, run is for running a set of go-files, whereas build is for building a package.</p></pre>bishopknight1977: <pre><p>If you're using Gogland for IntelliJ you need to specify the run configuration to package . I had the same problem until I changed it. </p></pre>thornag: <pre><p>You need to include all the files when running or building</p>
<p>go run ./... or go run *.go</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传