September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will show you how to use the aSimplePackage and anotherPackage packages in your own Go programs by presenting two small Go programs named usePackage.go and privateFail.go.
In order to use the aSimplePackage package that resides under the GOPATH directory from another Go program, you will need to write the following Go code:
package main
import (
"aSimplePackage"
"fmt"
)
func main() {
temp := aSimplePackage.Add(5, 10)
fmt.Println(temp)
fmt.Println(aSimplePackage.Pi)
}
First of all, if aSimplePackage is not already compiled and located at the expected location, the compilation process will fail with an error message similar to the following:
$ go run usePackage.go usePackage.go:4:2: cannot find package ...
Read now
Unlock full access