Home > Blockchain >  How do I import module from one go project(Common) to other go project (API)?
How do I import module from one go project(Common) to other go project (API)?

Time:12-16

I have a go project where the common functionality is implemented , and there is an another go project for the API which uses common functionality from the first project. API project uses the common project , the imports are done from git hub.

I have added a new functionality to the common project and trying to access that new functionality in API project . I have pushed the code to my branch in git hub (new code not there in master branch of common project) . How can I import the new functionality to API project

CodePudding user response:

you could import packages from specific branch like this

go get <path-to-repo>@<branch>

CodePudding user response:

You're probably looking for go get -u github.com/yourcommonproject. From go help get:

The -u flag instructs get to update modules providing dependencies
of packages named on the command line to use newer minor or patch
releases when available.

The -x flag might also be useful in debugging:

The -x flag prints commands as they are executed. This is useful for
debugging version control commands when a module is downloaded directly
from a repository.

Useful relevant links:

https://golang.cafe/blog/how-to-upgrade-golang-dependencies.html

https://go.dev/doc/modules/managing-dependencies

  • Related