go modules and local packages

120 views
Skip to first unread message

Sankar

unread,
Aug 8, 2020, 2:20:56 PM8/8/20
to golang-nuts
Hi

I have a monolithic source repository that is NOT in git, mercurial etc.

The directory structure is:

root
|
|--- mylib
|         | --- mylib.go
|         | --- go.mod
|--- svc1
|       | --- go.mod
|       | --- cmd
|                 | ---- svc1.go
|--- svc2
|       | --- go.mod
|       | --- cmd
|                 | ---- svc2.go

Here there is a `mylib` which is a common library. `svc1` and `svc2` are two golang http servers that come with their own `go.mod` files. Now I want to import the `mylib` in the `svc1` and `svc2` sources and the go.mod files.

Can someone tell me how to achieve this ? I can modify the go.mod of `mylib` to anything but cannot publish the sources to a VCS.

I tried adding the following in the go.mod files of svc1 and svc2 but it did not work.
replace (
my.lib latest => ../mylib latest
)

Any other suggestions to get this working ? Thanks.

Tamás Gulácsi

unread,
Aug 8, 2020, 2:24:41 PM8/8/20
to golang-nuts
Use one go.mod pee repo.

Sahas Subramanian

unread,
Aug 8, 2020, 2:29:58 PM8/8/20
to Sankar, golang-nuts
You could try moving mylib to your $GOPATH/src/, and 
    import "mylib" 
in the services.

--
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/3f4c0e55-d7c1-493a-b08b-dd2d05124447n%40googlegroups.com.

Sankar P

unread,
Aug 8, 2020, 2:42:18 PM8/8/20
to Sahas Subramanian, golang-nuts
> You could try moving mylib to your $GOPATH/src/, and
> import "mylib"
> in the services.

I tried that but could not get `go run cmd/svc1.go` from trying to
checkout a non-existent url (for the `mylib`). Can you share the
contents of the `go.mod` file for svc1 and mylib ?

Sankar P

unread,
Aug 8, 2020, 3:16:47 PM8/8/20
to Tamás Gulácsi, golang-nuts
> Use one go.mod pee repo.

That won't be possible. It is a monolithic repo. svc1 and svc2 may
need two different versions of a common dependency.

Gulácsi Tamás

unread,
Aug 8, 2020, 4:05:25 PM8/8/20
to Sankar P, golang-nuts
Then why are they in a monorepo?

AFAIK monorepos for strictly controlled dependenies and easier refactorings.

If two part needs different versions for something common, then they should live and evolve  separately.

From: Sankar P <sankar.c...@gmail.com>
Sent: Saturday, August 8, 2020 9:16:04 PM
To: Tamás Gulácsi <tgula...@gmail.com>
Cc: golang-nuts <golan...@googlegroups.com>
Subject: Re: [go-nuts] go modules and local packages
 

Sankar P

unread,
Aug 9, 2020, 1:01:28 AM8/9/20
to Gulácsi Tamás, golang-nuts
> Then why are they in a monorepo?
>
> AFAIK monorepos for strictly controlled dependenies and easier refactorings.
>
> If two part needs different versions for something common, then they should live and evolve separately.

This is a subset of a larger mono-repo. This repo has sources for
about 40 other services(sources for the binaries) and libraries, in
different languages. All our sources are kept in a single monolithic
repository (like Google, in some sense).

So should I setup some kind of a private modules repository (like
private npm repositories for js or pypi for python) where the library
source archives can be saved !? Is there no other way to do this for
multi-module repositories ?

Space A.

unread,
Aug 9, 2020, 6:44:24 AM8/9/20
to golang-nuts
I had the same situation and this worked perfectly:

replace mylib => ../mylib

If it doesn't - check paths, name of the "mylib" module, etc



суббота, 8 августа 2020 г. в 21:20:56 UTC+3, Sankar:

Sankar P

unread,
Aug 9, 2020, 8:31:10 AM8/9/20
to Space A., golang-nuts
> I had the same situation and this worked perfectly:
>
> replace mylib => ../mylib
>
> If it doesn't - check paths, name of the "mylib" module, etc

Thanks. It worked. I strongly feel like I tried the same yesterday and
it didn't work, but probably mis-typed the name in the module.
Reply all
Reply to author
Forward
0 new messages