Go mod replace a package with a repository url

I’d like to replace “encoding/json” with “https://github.com/segmentio/encoding

One option would be to replace all import statements in every file that imports JSON. This is not ideal since 1) it affects many files 2) I have to remember the new import name for all future files. To avoid this, I would like to use the replace directive in go mod such as replace encoding/json => github.com/segmentio/encoding/json. However, this command produces the error go.mod:5: replacement module without version must be directory path (rooted or starting with ./ or ../)

Is there any way to alias a package without editing every single import statement?

Alternatively, is there a way to find the directory where a module is installed and use that in the replace directive?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.