Go(golang)包,包含多个文件夹

问题描述:

Is it possible in Go (golang) to have a package consisting of several .go files from different folders?

I am trying to make a subfolder inside of the main folder, and compiler says that it cannot find definitions ("undefined" error). When all the files are in the same folder, compilation does not give errors.

Thanks.

在Go(golang)中是否可能有一个包含多个来自不同文件夹的.go文件的程序包? p>

我正在尝试在主文件夹中创建一个子文件夹,并且编译器表示找不到定义(“未定义”错误)。 当所有文件都在同一文件夹中时,编译不会给出错误。 p>

谢谢。 p> div>

No, this is not possible.

If you want to use folders inside your go project you have to use several packages.

NOT VALID

myproject
| -- main.go (package main)
| -- routes.go (package main)
+ -- models
     | -- db.go (package main)
     | -- mymodel.go (package main)

VALID

myproject
| -- main.go (package main)
| -- routes.go (package main)
+ -- models
     | -- db.go (package models)
     | -- mymodel.go (package models)