Home >Backend Development >Golang >How Can I Access Local Packages Within My Go 1.11 Modules?
Accessing Local Packages within Go 1.11 Modules
Problem Statement
When attempting to access a local package in a Go module with a project structure similar to the one described below, the compilation fails with a "cannot find module" error.
Solution
To access local packages within a Go module, you need to modify the project's go.mod file and use the replace directive. This directive allows you to specify a local path for a package that is not available in a remote repository.
Steps to Resolve the Issue
Define the Modules:
Modify go.mod File:
Add the following lines to the go.mod file:
Import the Package:
In main.go, import the desired package from otherModule:
Additional Information
The above is the detailed content of How Can I Access Local Packages Within My Go 1.11 Modules?. For more information, please follow other related articles on the PHP Chinese website!