what is a minimal setup for compiling go programs in module mode?

80 views
Skip to first unread message

fge...@gmail.com

unread,
Mar 24, 2021, 5:40:32 AM3/24/21
to golang-nuts
Assuming GO111MODULE=on, if I don't want to publish anything and I
only want to build go code in the local filesystem, referencing only
go packages in the local filesystem.

Can I do that without local version control software and a private module proxy?

After reading most module documentation on golang.org, I still can't
answer this question.
If anybody already does that, could you please share your setup?
If a local version control and a private module proxy is needed, could
you also please share the details?

Thanks!

fge...@gmail.com

unread,
Mar 24, 2021, 6:12:52 AM3/24/21
to golang-nuts
Sorry I forgot 1 more expectation/boundary condition: I'd like to be
able to tar both go code in the local filesystem and the referenced go
packages in the local filesystem and copy it to a different OS to
different absolute paths?
I believe I can't use replace?

Miguel Angel Rivera Notararigo

unread,
Mar 24, 2021, 6:34:16 AM3/24/21
to fge...@gmail.com, golang-nuts
You can use the vendor folder, just copy (or symlink, but you will need to keep them updated) what you need there and will work.

fge...@gmail.com

unread,
Mar 24, 2021, 6:56:17 AM3/24/21
to Miguel Angel Rivera Notararigo, golang-nuts
Thanks, that's exactly what I was looking for!

For the next go programmer looking for a solution in similar situation:
on page https://golang.org/ref/mod#vendoring
"... or to ensure that all files used for a build are stored in a
single file tree"

jake...@gmail.com

unread,
Mar 24, 2021, 12:19:13 PM3/24/21
to golang-nuts
> I believe I can't use replace?

I'm glad the vendoring solution is what you want. But IIUC what you are trying to do, then there is no reason you can not use replace. For example:
require gergrly/otherpackage v0.0.0
replace  gergrly/otherpackage => ../otherpackage
This works for me. You could then tar, the outer folder.


Amnon

unread,
Mar 24, 2021, 12:34:56 PM3/24/21
to golang-nuts
You can just tar up your ~/go/pkg/mod directory (plus your own sources) and you will be good.

fge...@gmail.com

unread,
Mar 24, 2021, 1:25:33 PM3/24/21
to Amnon, golang-nuts
Thanks to both you and jake!
I remembered something similar to "import path should not be relative
paths". (Otoh the replace directive is not an import path, so I should
have checked before asking this.)
Anyways, thanks again!
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/03ecf1f1-7441-41cc-8e76-6049d62e3dccn%40googlegroups.com.
>
Reply all
Reply to author
Forward
0 new messages