Import package & type

后端 未结 1 467
野的像风
野的像风 2021-01-29 15:02

Here is my problem and my project structure

src
|-->config
       |--> config.go
|-->otherPackage
       |--> otherFile.go
|-->main.go


        
相关标签:
1条回答
  • 2021-01-29 15:47

    You cannot "import from a package". All you can do is "import the whole package". That means if you import "full/import/path/of/foo" and that package declared itself to be called foo via package foo at the beginning, then everything in this package has to be qualified by foo:

    foo.Config
    

    If you package is called config than declaring a variable config will shaddow the whole package: so you have to:

    1. Rename the config variable to e.g. cfg
    2. Reference Config from package config with its qualified name config.Config
    0 讨论(0)
提交回复
热议问题