This is a creation in Article, where the information may have evolved or changed.
Because I forgot to install the Chinese input in this OS, I has to use 中文版 input.
The first problem which I ran into was "how to import the local file in Golang"
First, it may is my fault but I really didn ' t see any documents say so if you want to import a local file in another Go File, you should create a folder to put the imported file. Below is my case:
I created a file said "Example2.go", then typed some codes:
int int { return A + B}
I wanted to import it in another file said "Example1.go"
Package Mainimport ( "fmt" "./example2" ) Func main () { fmt. Println ("Hello go! " ) FMT. Println (example2. ADD (1,2))}
When I tried to run the Example1.go file, the go runtime threw an error said "couldn ' t find the example2". What ' s the problem? Is Gopath not set? Is Example2.go not compiled? Finally, I found it is the folder structure problem. My orignal folder structure likes this
GOWORKSPACE-PKG-SRC -Example1.go -Example2.go-bin
But Go 1.4 doesn ' t support import a single file as a package. So I had to put the ' Example2.go ' in a folder said "Package2"
GOWORKSPACE-PKG-SRC -Example1.go -Package2 -Example2.go-bin
Then change the code
Package Mainimport ( "fmt" "package2 " ) Func main () { fmt. Println ("Hello go! " ) FMT. Println (example2. ADD (1,2))}
It works. So it means a, refers to a, folder in the Golang.