I have a small module that contains some shared code. The module looks like the following :
Shared
├── go.mod
├── go.sum
├── logging
│ └── logger.go
└── db-utils
├── db.go
If I'll try to build the Shared module from inside the directory I'm getting an error that no go file available under this module.
bash-3.2$ go build .
no Go files in /Users/xxxx/go/src/Shared
Is there a way to build a Go module that only has packages inside and doesn't have a main.go file? The motivation here is to use those packages in other go modules that can't access the internet or private repo in order to retrieve the packages.
go build
you will have to list them both at the end of the command, or import them with blank imports in a .go file in.
– Syceego build ./...
– Heparinmain
packages. This has been the case for some time. See github.com/golang/go/issues/28152 and golang.org/pkg/go/build/#hdr-Binary_Only_Packages – Syceemain
package.main()
is the entry point to an executable, without it you cannot build an executable. – Vorous