I'm migrating dep project into go modules, and some Go files in this project import proto files, but when I execute go mod tidy
, it says that cannot find the package where proto files are. Project's structure:
version_service
proto
authentication
authentication.proto
version
version.proto
repository.go
I'm importing like this in repository.go
pb "proto/version"
And i have this:
proto/version: package proto/version is not in GOROOT
How import this files?
GOROOT is meant to "store" Go native packages, so you shouldn't use it for your own packages, instead, you need to use Go Modules.
You can interpret Go Modules almost like a native package manager for your Go projects, for example, in your project with the following structure:
In you shell you can start the Go Modules with
go mod init package.name
, in your case package.name could be proto, so using your project root as reference you could import packages using proto/version