Home > Blockchain >  Replacing inconvenient package name. Got error: replacement module without version must be directory
Replacing inconvenient package name. Got error: replacement module without version must be directory

Time:05-13

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:

What I tried:

  1. 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
  1. 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" .

  • Related