我对Golang并不陌生,并试图使一个简单的REST api应用程序正常工作。
最初,一切都很好,因为所有代码都在
但是,现在我处于一个阶段,需要开始将代码重构为子目录和包。 不幸的是,我无法成功编译该应用程序。
我的
当前应用位于:
这就是我当前的代码组织:
这是我的
这是中间件
这是我从应用程序的根目录运行
The Go Programming Language Specification
Qualified identifiers
A qualified identifier is an identifier qualified with a package name
prefix. Both the package name and the identifier must not be blank.
1 QualifiedIdent = PackageName"." identifier .A qualified identifier accesses an identifier in a different package,
which must be imported. The identifier must be exported and declared
in the package block of that package.
1 math.Sin // denotes the Sin function in package mathImport declarations
An import declaration states that the source file containing the declaration depends on functionality of the imported package (§Program
initialization and execution) and enables access to exported
identifiers of that package. The import names an identifier
(PackageName) to be used for access and an ImportPath that specifies
the package to be imported.
1
2
3 ImportDecl ="import" ( ImportSpec |"(" { ImportSpec";" }")" ) .
ImportSpec = ["." | PackageName ] ImportPath .
ImportPath = string_lit .The PackageName is used in qualified identifiers to access exported identifiers of the package within the importing source file.
It is declared in the file block. If the PackageName is omitted, it
defaults to the identifier specified in the package clause of the
imported package. If an explicit period (.) appears instead of a name,
all the package's exported identifiers declared in that package's
package block will be declared in the importing source file's file
block and must be accessed without a qualifier.The interpretation of the ImportPath is implementation-dependent but it is typically a substring of the full file name of the compiled
package and may be relative to a repository of installed packages.Implementation restriction: A compiler may restrict ImportPaths to non-empty strings using only characters belonging to Unicode's L, M,
N, P, and S general categories (the Graphic characters without spaces)
and may also exclude the characters !"#$%&'()*,:;<=>?[]^`{|} and the
Unicode replacement character U+FFFD.Assume we have compiled a package containing the package clause package math, which exports function Sin, and installed the compiled
package in the file identified by"lib/math". This table illustrates
how Sin is accessed in files that import the package after the various
types of import declaration.
1
2
3
4
5 Import declaration Local name of Sin
import "lib/math" math.Sin
import m"lib/math" m.Sin
import ."lib/math" SinAn import declaration declares a dependency relation between the importing and imported package. It is illegal for a package to import
itself, directly or indirectly, or to directly import a package
without referring to any of its exported identifiers. To import a
package solely for its side-effects (initialization), use the blank
identifier as explicit package name:
1 import _"lib/math"
错误
说您在包
错误
表示您尚未在包
"合格的标识符是带有包名称前缀的合格标识符。合格的标识符访问不同包中的标识符,必须将其导入。"
例如,在包