In the process of learning go I was playing around with making my own libraries. Here is what I did: in my $GOPATH/src I have two folders: mylibs
and test
. The test
folder has a file called test.go
which contains
package test
import "mylibs/hi/saysHi"
func main() {
saysHi.SayHi()
}
The mylibs
folder contains another folder called hi
, which has a file called saysHi.go
containing:
package saysHi
import "fmt"
func SayHi() {
fmt.Printf("Hi
")
}
So the directory structure looks like this:
- GOPATH/src
- test
- test.go
- mylibs
- hi
- saysHi.go
The problem is that when I try to compile test
it complains saying
cannot find package "mylibs/hi/saysHi" in any of:
[...]
$GOPATH/src/mylibs/hi/saysHi (from $GOPATH)
I have deliberately made the directory structure deeper than necessary. If I make a simpler directory structure where I place saysHi.go
in $GOPATH/saysHi/saysHi.go
then it works.
But I don't see a reason for why this wouldn't work. Any ideas?