I'm created a project structure like,
main.go
and foo/bar.go
In main.go, imported foo package and used as foo.functionName(). Now i need to write swagger document in bar.go. When i did, ended with the following error message,
unable to determine package for /PATH_TO_PROJECT/foo/bar.go
Ensure in foo/bar.go
the package declared is package foo
. Then the function you want to access in the main.go
file should start with a capital letter. i.e.
foo/bar.go
package foo
// PrintBar with extra txt
func PrintBar(txt string) string {
return "bar with txt " + txt
}
Then in main.go
package main
import (
"fmt"
"github.com/username/project/foo"
)
func main() {
fmt.Println("in main.go")
fmt.Println(foo.PrintBar("from main.go"))
}
Try enabling Debug mode for swagger by adding DEBUG=1
in front of your swagger command. This should print you what are the paths considered.
If you look at the source code where this error is thrown, you will see this error only happens when file is not in the $GOPATH
. Double check that you have the program under $GOPATH/src
.