I was trying to create a small program using clean architecture . So I have some problems when I want to call a function from one package to another one. For example,
In main.go I have :
import (
“infrastructure”
)
a := infrastructure.Test(“hello”)
When I made go build I receive this error: undefined infrastructure.Test
Assuming project is under your $GOPATH then your main.go should look like this:
package main
import (
"fmt"
"project/infrastructure"
)
func main() {
a := infrastructure.Test("hello")
fmt.Println(a)
}
If you are not familiar with the concept of $GOPATH please read How to Write Go Code. Here are some helpful videos that show the basics of workspaces, testing etc. [1][2].
If you are already familiar with the basics and you are looking for a good way to organize your code then I highly recommend reading Standard Package Layout.