Go: local import in non-local package

后端 未结 6 2087
孤街浪徒
孤街浪徒 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:55

    You can't use local import when specifying a non-local package to go install. If you want the local import to work, first change working directory to src/jacob.uk.com then execute go install (without specifying the package).

    Of course having the helloworld.go you provided you will get an compile error: imported and not used. But once you use something from the imported greeting package, it should compile.

    But you shouldn't use local imports at all. Instead write:

    import "jacob.uk.com/greeting"
    

    And doing so you will be able to compile/run/install it from anywhere.

提交回复
热议问题