I'm making a Go program and have created a module to divide it. Here is my working tree (the minimal
directory is in $GOPATH/src/
):
minimal/
├── main.go
└── ui
├── go.mod
├── go.sum
└── ui.go
In the ui
module I have the following:
package ui
import "github.com/satori/go.uuid"
func SomeFunction() {
id, err := uuid.NewV4()
if err == nil {
print(id.String())
} else {
print(err)
}
}
The main
package uses this module as follows
package main
import "minimal/ui"
func main() {
ui.SomeFunction()
}
Here is the go.mod
file:
module minimal/ui
go 1.14
require github.com/satori/go.uuid v1.2.0
When running go build
in the main package folder, everything works and the binary is generated. However, when building only the ui
module, it gives the following compilation error:
ui$ go build
# minimal/ui
./ui.go:6:10: assignment mismatch: 2 variables but uuid.NewV4 returns 1 values
You can check https://github.com/satori/go.uuid to see that the function returns two values. What has me puzzled is that building the main package works, but the module doesn't. Why is that?