Problem
In go.mod file I wrote:
module github.com/Siiir/vector
go 1.17
require github.com/huandu/go-clone v1.3.2 // indirect
replace clone => github.com/huandu/go-clone[v1.3.2]
It says that I cannot do such a replacement.
I actually solved my problem with the name of imported package.
It is convenient & working without that dash. I found that I can use clone.something
to refer to a function.
No need to type go-clone.something
.
Anyway, assume that a package name is indeed crazy or inconvenient. How can I replace it?
What I've seen:
- I've seen a sibling question: go modules - replace does not work - replacement module without version must be directory path (rooted or starting with
What I tried:
- Working with terminal:
- go mod edit -replace=clone=github.com/huandu/go-clone
got:go: -replace=clone=github: unversioned new path must be local directory
- manual editing:
- Attempts like: replace clone => github.com/huandu/go-clone[v1.3.2]
got:replacement module without version must be directory path (rooted or starting with ./ or ../)
CodePudding user response:
Anyway, assume that a package name is indeed crazy or inconvenient. How can I replace it?
You cannot.
And you should not. The import path is something you write just once in the import
declaration and the package name can be changed on a per file level with import nicename "something.you.think/is-totally/inconvenient/and/unacceptable-to/your_taste"
.