Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go : 'use of internal package not allowed ' when running a Go project forked from a GitHub repository

Tags:

github

go

I'm getting used to Go, and trying to understand how it works.

So I'm trying to run the test code from my repository zoonoo/go-ethereum, forked from the original repository ethereum/go-ethereum.

When I run go test . under the eth directory, I get the following error :

eth/api.go:37:2: use of internal package not allowed

37th line of eth/api.go is as follows : "github.com/ethereum/go-ethereum/internal/ethapi"

Does this mean when you fork a go repository, you have to change the path of all dependencies within the code to run the code?
Does Go package system support repository fork at all?

like image 212
zoonoo Avatar asked Oct 21 '17 06:10

zoonoo


2 Answers

As illustrated in another Go project:

Cloning a fork

If you wish to work with fork of InfluxDB, your own fork for example, you must still follow the directory structure above. But instead of cloning the main repo, instead clone your fork. Follow the steps below to work with a fork:

export GOPATH=$HOME/gocodez
mkdir -p $GOPATH/src/github.com/influxdb
cd $GOPATH/src/github.com/influxdb
git clone [email protected]:<username>/influxdb

Retaining the directory structure $GOPATH/src/github.com/influxdb is necessary so that Go imports work correctly.

Replace InfluxDB name/URL by your project, and the same idea applies.

In your case, the GitHub fork is only there for you to push your contribution back to it, and to make Pull request from it.
It won't serve as a source for go get to work, since the packages wouldn't match your GitHub for repo URL.

like image 174
VonC Avatar answered Oct 01 '22 04:10

VonC


This is because internal packages in go can only be imported by packages in the same directory root. It's kind of like package private classes in java. If you want to edit the code without having to rename all package imports you need to maintain the same folder structure that the package expects so if github.com/zoonoo/go-ethereum is in your $GOPATH rename the directory to github.com/ethereum/go-ethereum or create a symbolic link and work from the linked directory instead.

like image 35
Clive Makamara Avatar answered Oct 01 '22 02:10

Clive Makamara