Go: local import in non-local package

后端 未结 6 2073
孤街浪徒
孤街浪徒 2020-12-08 06:16

I have the following file structure:

.
├── bin
│   └── hello
├── pkg
└── src
    └── jacob.uk.com
        ├── greeting
        │   └── greeting.go
        └─         


        
6条回答
  •  庸人自扰
    2020-12-08 06:42

    If you just want to share code between separate files and not separate packages, here's how to do it:

    You don't need to import, you just have to put the source files in the same directory and specify the same package name at the top of each file, and then you can access all the public (Uppercase) functions and types, by referencing them directly, that is, SomeFunction() and not somepackage.SomeFunction()

提交回复
热议问题