Packages are the basic unit of creating separated and reusable code. From inside the package, you refer to its identifiers (identifiers declared in the package) by their name. From the "outside" (from other packages), you import the package and you refer to its identifiers using a qualified identifier, which is
QualifiedIdent = PackageName "." identifier .
When a package consists of multiple files, each identifier declared in any of the package's files will belong to the package block. Quoting from Spec: Declarations and scope:
The scope of an identifier denoting a constant, type, variable, or function (but not method) declared at top level (outside any function) is the package block.
What this means is that you can't have the same identifier declared in 2 files of the same package.
If you think about it, this is how it should be. What happens if someone from the outside writes basic.Header
? Which Header
should that mean?
One option is to put them into 2 separate packages: req
and resp
, then you can refer to them as req.Header
and resp.Header
, and you know exactly what they mean just by looking at these qualified identifiers.
If you don't want 2 packages, simply rename them. Give them meaningful names, such as ReqHeader
and RespHeader
, and then you may refer to them like basic.ReqHeader
and basic.RespHeader
.