Jim, I used replace this way just yesterday. It works fine, but is not
easily discoverable as a process and it took me a minute or two to figure
it out. Also, one must be sure to remove the replace directive before
releasing the code, which is an easy detail to forget.

The same trick (and required care) applies when patching a library.

Modules work well but you do need to read and understand the documentation.
The posts in blog.golang.org are good. You can start here:
https://blog.golang.org/v2-go-modules

-rob




On Wed, Jan 13, 2021 at 6:53 AM Jim Ancona <j...@anconafamily.com> wrote:

> I have a third use case for replace:
>
> 3. Simultaneously developing a library and client for that library. For
> example, if I have a library to access a network service or piece of
> hardware and want to extend its API, I find that working on the client
> along with the library helps me iterate to a good API. I use replace to get
> that to work. But I think that newcomers to the language are unlikely to
> run into that case either.
>
> Jim
>
> On Tue, Jan 12, 2021 at 9:26 AM 'Axel Wagner' via golang-nuts <
> golang-nuts@googlegroups.com> wrote:
>
>> On Tue, Jan 12, 2021 at 2:49 PM Kevin Chadwick <m8il1i...@gmail.com>
>> wrote:
>>
>>> On 1/12/21 12:37 PM, Axel Wagner wrote:
>>> > Again, would be interesting how other languages can make this simpler,
>>> because I
>>> > genuinely can't imagine.
>>>
>>> The issue is that I believe go avoids files in order to speed up
>>> compilation.
>>>
>>
>> I don't believe it is.
>>
>>
>>> It's just I don't believe the replace directive was meant for this and
>>> yet upon googling.
>>
>>
>> I tend to agree. I still do not understand why you feel the need to use
>> it. It has two fairly limited uses: 1. overwrite the dependency of one of
>> your dependencies, e.g. to use a fork which contains critical patches you
>> need. And 2. work with a local fork of a dependency, for experimentation
>> (e.g. to find a bug or try out an unpublished API). Neither of these are
>> things that should be encountered by newcomers to the language - or very
>> often at all.
>>
>> If you are using replace as part of your regular workflow, I do agree
>> that you are probably misusing it. It's just hard to understand why, from
>> what you said so far (barring the "I don't have an internet connection and
>> want to use something from my module cache" case, which I find surprising,
>> if that's part of your regular workflow).
>>
>> It is the only way that I have found. mod
>>> vendor doesn't seem to do what I want.
>>>
>>> They are fairly similar otherwise.
>>>
>>> Flutter create
>>> open lib/main.dart
>>> add import to file locations in any dart files where you wish to access
>>> that
>>> particular code (like in most languages)
>>> add package to pubspec.yaml
>>> IDE asks to run flutter pub get
>>> add import referencing package where needed
>>>
>>> vs
>>>
>>> go mod init
>>> edit .mod with weird replace line that links a domain to a file location
>>> add import matching replace directive domain/url
>>> go get package
>>> add import for the package
>>>
>>> As I said. I should probably just set up a local git server and sync up
>>> that
>>> way. symlinks were only an issue in some programs and only when using
>>> Windows too.
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/8417466a-deb0-98f6-3635-3240278dbcc7%40gmail.com
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/CAEkBMfF6axmeHxYMecoHfR%2BhBVdto_froMGVswRYaoKYWodHnQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/golang-nuts/CAEkBMfF6axmeHxYMecoHfR%2BhBVdto_froMGVswRYaoKYWodHnQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAKYY9A%2BKrPwHSK00VjQcsyZoKxumaHWoR-pUi1Jww7hfRtijBA%40mail.gmail.com
> <https://groups.google.com/d/msgid/golang-nuts/CAKYY9A%2BKrPwHSK00VjQcsyZoKxumaHWoR-pUi1Jww7hfRtijBA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOXNBZSqNBfF4V_EEPqKV2g%2Bz2O7jAAAFL3q3KYzaXYUSMYdFQ%40mail.gmail.com.

Reply via email to