我有一些Golang問題並且包含了包裹。我有scructureGolang進口配套包
src/
├── hello_world
│ ├── hello.go
│ └── math
│ └── add.go
hello.go文件包含以下代碼:
package main
import (
"fmt"
math "hello_world/math"
)
func main() {
fmt.Println("Hello World")
x := math.add(6, 5)
}
和add.go
package math
func add(x, y int) int {
return x + y
}
當我做go run hello go
我看到:
[email protected]:~/go/src/hello_world$ go run hello.go
# command-line-arguments
./hello.go:10: cannot refer to unexported name math.add
./hello.go:10: undefined: "hello_world/math".add
GOPATH:
[email protected]:~/go/src/hello_world$ echo $GOPATH
/home/evgen/go
如何解決?謝謝!
哈!我真笨!非常感謝你! –