I am new to go lang and I m trying out my first app. I hit a roadblock while importing a package from another go file.
I have two go files. 1. hello.go with main package. 2. data.go with data package.
The code inside hello.go is
package main
import (
"datatypes/data"
"fmt"
)
func main() {
fmt.Print("Hello world!!\n")
/* calling the first function from another function */
myFirstFunction()
}
func myFirstFunction() {
fmt.Print("This is the first function\n")
data.WorkingWithDataTypes()
}
data.go code is
package data
import "fmt"
/*WorkingWithDataTypes is a function to work with go lang data types */
func WorkingWithDataTypes() {
x := 10
fmt.Print(x)
}
When I run the main function by running go run hello.go I am getting the below error
**hello.go:10:2: cannot find package "firstapp/data" in any of:
/usr/local/go/src/firstapp/data (from $GOROOT)
/Users/home/workspaces/Go/Project1/src/firstapp/data (from $GOPATH)**
I set my go path as /Users/home/workspaces/Go/Project1. I am not sure where I make the mistake. any help?
I set the GO PATH as
As per the go doc for go path
I created the project structure as below and put my code below src folder.
src/datatypes has the package data. src/main has the package main.
But still go run hello.go is failing as it is not able to find the package datatypes/data