go: Use of internal package ... is not allowed

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go 1.11rc1

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

win 10x64 set GOARCH=amd64 set GOBIN=d:\soft\bin set GOCACHE=C:\Users\Alexander.go\cache set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\Users\Alexander.go\go set GOPROXY= set GORACE= set GOROOT=d:\soft\go set GOTMPDIR= set GOTOOLDIR=d:\soft\go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=D:\Dev\go\scratch\go.mod set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ALEXAN~1\AppData\Local\Temp\go-build973572782=/tmp/go-build -gno-record-gcc-switches

What did you do?

scratch/go.mod

module scratch

scratch/main.go

package main

import "scratch/internal"

func main() {
	internal.F()
}

scratch/internal/f.go

package internal

func F() {}

go build main.go

What did you expect to see?

Compilation success

What did you see instead?

main.go:3:8 use of internal package scratch/internal not allowed

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@AlekSi Actually it ended up being an issue with my local directory structure. I’m new to an organization, and I was told to clone my repo into $GOPATH/src/github.enterprisename.com instead of manually creating a new folder called /myorg in which to clone my repo into. My linter was complaining about something valid, yet my build process was still succeeding, because it looked to the linter as if I was importing from a separate repo altogether when I was working on the project. Hopefully this helps someone else with this literally rookie mistake…

Basiscally, my issue was: I cloned myapp into $GOPATH/src/github.enterprisename.com instead of $GOPATH/src/github.enterprisename.com/myorg, so the docker build worked but the linter was confused. (unforced developer error)

@AlekSi There is no specification that you can’t in the concerned versions of go: https://golang.org/doc/go1.12