无法将本地包调用为主

I feel like this is probably an over-asked question on SO yet here it is again. I'm finding this simple task incredibly tedious in Go. Note that I have GO11MODULES set to ON, I'm not sure if this effects the whole package system (it shouldn't is what I'm assuming).

I have a package called "users" which contains a compiled Protocol Buffer (from a .proto file). I want to store it alongside a number of other definitions in a folder called protos. So that my structure looks like so:

- main.go
- protos
   - users.go
   - users.proto
   - analytics.go
   - analytics.proto

Pretty simple structure. Within the users.go file I'm defining package protos. Within main.go I'd like to import users "protos/users". When I do so I get this: build command-line-arguments: cannot load protos/users: cannot find module providing package protos/users.

I've followed (I think) other sample code that has done the same thing. Note that the folder structure is within $GOPATH/src/myapi.

Why is this more complicated than its proving to be?

If you are using package protos, then the package is protos. protos/users does not exist. Packages and package imports are directory-level, not file-level. The full import statement depends on the module declaration in your go.mod file, which defines the root of imports. E.g., if your go.mod begins with

module github.com/me/myapp

Then your import would be

import "github.com/me/myapp/protos"

This answer assumes that GO111MODULE is set to on. The question shows that you are setting GO11MODULES. I assume that this is a typo. Fix it if it's not a typoo.

Add file go.mod in same directory as main.go with the following contents:

module myapi

Change main to import "myapi/protos" instead of "protos/users"