Go modules has removed that restriction, although previously you could also get around it by avoiding Go’s build system (e.g. use Bazel instead). Some people would also just stick their go code in <repo>/go/src/example.com/pkgname, which is not that different from the way you might structure Java code anyway.