Go: local import in non-local package

I have the following file structure:

. ├── bin │ └── hello ├── pkg └── src └── jacob.uk.com ├── greeting │ └── greeting.go └── helloworld.go 5 directories, 3 files

With the following GOPATH

/Users/clarkj84/Desktop/LearningGo

Upon executing /usr/local/go/bin/go install jacob.uk.com within the src folder, I get the error local import "./greeting" in non-local package

helloworld.go:

package main; import "./greeting" func main() { }

-------------Problems Reply------------

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.

Category:go Views:0 Time:2018-12-06
Tags:

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.572 (s). 12 q(s)