Learn to Use replace in go.mod

Опубликовано: 02 Октябрь 2021
на канале: rwxrob
2,174
38

The replace keyword in go.mod allows you to work on several packages, with different repos, at the same time, or, to test changes locally before pushing them.

Unfortunately, it is rather easy to leave the replace in your go.mod file and forget and commit it. Until rather recently, that meant other projects depending on your module would fail to compile trying to locate your local path on their build machines. These days go won't even compile or install the module if there is a replace in the go.mod file.

Even so, committing to a production repo with replace could be embarrassing so might want to add the following .git/hooks/pre-commit hook (don't forget to chmod +x) to prevent any commit of go.mod that has the word replace in it, which you could easily modify to check that it isn't commented out (// replace should be allowed). This script checks for jq and if not found uses grep instead:

[code snipped]

Tags:

#golang #tips #replace

Thanks sponsors, subs, and followers:

GitHub: https://github.com/sponsors/rwxrob
Twitch:   / rwxrob  
Twitter:   / rwxrob  
Discord:   / discord  

See http://rwxrob.tv/schedule for scheduled streams.

[ZETID:20211002150304]
https://github.com/rwxrob/zet/tree/ma...


Смотрите видео Learn to Use replace in go.mod онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь rwxrob 02 Октябрь 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,174 раз и оно понравилось 38 людям.