I have many projects that do different things each, and most of them use packages that I have already created before.
For example in the
custom directory I have these three packages:
I want to use
custom in all my projects, like this:
I solved it by copying the
custom folder to the directory:
That way I can import as in the example I showed before, my problem comes when using the
go mod vendor command it copies all the dependencies of my project to a folder called
vendor but totally ignores my
So what can I do to make Go detect my dependencies as
Any ideas would be welcome but I have to clarify that
custom cannot be uploaded to the internet.
The key is to use
replace in your go mod file to point to your local modules. You’ll need a go.mod in your local packages to make them modules. Here’s a description https://levelup.gitconnected.com/import-and-use-local-packages-in-your-go-application-885c35e5624
It is not comfortable to use.
Then you need to push your modules to GitHub or any other compatible service.
What do you call that kind of service where Go requests the package from a server? To see if I can create a local version.
Or can you help me with a link to a tutorial on this? Because the results I find don’t help.
I’m pretty sure that’s because you put your
custom folder into
C:\Program Files\Go\src, so the compiler thinks
custom is a package in the standard library and shouldn’t go into
The only way that I know how to use a different package that isn’t online is using the
replace directive in the go mod file like mje said. Basically:
my-go-src-directory/my-other-project/go.mod (and every other project that uses
custom), I have:
http://github.com/skillian/custom => ../custom
This works even if
custom never gets uploaded to github.com.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.