I have a Go module whose name is 'tatata'. It is only developed in my machine and thus it does not contain any path to any URL in the module name.
If I have only one main
package in my module it works correctly.
However, if I create two packages in the module, I am experiencing some problems.
This is the tree:
./|
|- go.mod
|-src
|- main
| | - main.go
|
|- api
| - api.go
The content of the files:
go.mod
module tatata
go 1.13
main.go
package main
import "fmt"
import "tatata/api"
func main() {
fmt.Println("Hello world")
api.Test1()
}
api.go
package api
import "fmt"
func Test1() {
fmt.Println("Testing API")
}
When I try to build, I issue go build ./src/main
and I get the following error:
build tatata/src/main: cannot load tatata/api: malformed module path "tatata/api": missing dot in first path element
Now, if I try to put a dummy dot, like renaming the module to tatata.com
I get the error build tatata.com/src/main: cannot load tatata.com/api: cannot find module providing package tatata.com/api
as obviously my package/module is not available in that URL.
GOPATH
is empty, i.e. not set.
Questions:
a) What is the right way, i.e. naming of modules and imports when using multiple packages inside a single Go module?
b) Is it impossible to have a Go module without dots in its name?!
c) Can you point me to any working example that has a building set-up with a single go module and multiple packages in the module?