I'm trying to make palyable example on godoc.
- OS X Yosemite 10.10.5
- Go: go1.7.4 darwin/amd64
test code: $GOPATH/src/hoge/hoge_test.go
package hoge_test
import (
"fmt"
"hoge"
"testing"
)
func ExampleHoge() {
fmt.Println(hoge.Hoge())
// Output:
// hoge!!
}
The test passes:
$ go test hoge
ok hoge 0.011s
Godoc
$ godoc -play -http=:8080
I can see the hoge
package's example playground as I expected on a web browser, but an error below occurs when I 'Run' the example.
tmp/sandbox389904218/main.go:5:2: cannot find package "hoge" in any of:
/usr/local/go/src/hoge (from $GOROOT)
/go/src/hoge (from $GOPATH)
I set my own GOPATH, but it's not /go
as shown in the error.
What I need to run examples.
Additional
I've got a reason of the error above. Godoc playable example redirects to play.golang.org to run the code, so the GOPATH in the error seems to be on the play.golang.org environment.
I'm still not sure how to run my own pkg example though...