Problem in understanding of package access

Hi All,

I am a new bee in Golang and trying to understand the concepts of Go and the best way to understand the go is “start writing code”.

So I am working on a project in but i am facing problem with package.
Now the problem statement is I am using go modules(i.e i done have my project on GOPATH).I ran the go mod init{my-repo}/myproject

The project structure is


Now the Code of cfg.go is

package internal

import “fmt”

func Test(){
fmt.Println(“This is just for testing”)

The out put of go.mod is


go 1.12

The main.go file looks like

package DBCleanUpJob

import “./internal”

func main() {

Now when i run this code with "go build main.go " it throws

main.go:3:8: unknown import path “_/Users/rajeshjain/projects/RiversProjects/DBCleanUpJob/internal”: internal error: module loader did not resolve import

Can you please help me with this …why am i getting this exception.

Other then this I was reading few blogs and where i discovered that internal module in a project is used to restrict the access of the package till that project as go used to have only to access local and global…so to overcome that we use internal.And internal can be accessed by the packages which are higher in the hierarchy to the internal i.e a/b/c/internal/d/e/f then a/b/c will be able to access the internal package…but what is the case for the packages which exists at the same level of internal…will they be able to access it.

Other then this few people in the blogs suggested that we need to create the project in the GOPATH and then access the internal project…then it is confusing for me as if we have to do that then what is the need to module which are introduced in Go…its a failure of that.

Thanks in advance.

Hi. I would import

1 Like


But for that do i need to copy the code to that location??

If i have to copy it there then whats the point of using go mod.

1 Like

Sorry I thought the code was in the folder internal which is a subfolder of DBCleanUpJob

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.