viper: Viper doesn't work with etcd
import (
"github.com/spf13/viper"
_ "github.com/spf13/viper/remote"
)
func main() {
if err := viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001","/config"); err != nil {
panic(err)
}
viper.SetConfigType("yaml")
if err := viper.ReadRemoteConfig(); err != nil {
panic(err)
}
}
I have error:
panic: codecgen version mismatch: current: 8, need 10. Re-generate file: ...my-app/pkg/mod/github.com/coreos/etcd@v3.3.10+incompatible/client/keys.generated.go
I tried
go get github.com/ugorji/go v1.1.1
and had error:
../pkg/mod/github.com/coreos/etcd@v3.3.10+incompatible/client/keys.generated.go:15:2: unknown import path "github.com/ugorji/go/codec": ambiguous import: found github.com/ugorji/go/codec in multiple modules:
github.com/ugorji/go v1.1.1 (...my-app/pkg/mod/github.com/ugorji/go@v1.1.1/codec)
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 (...my-app/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 21
Commits related to this issue
- Downgrade ugorji/go/codec from 1.1.2 to 1.1.1 Codec version has been changed in 1.1.2, but current tagged versions of etcd are compatible only with 1.1.1. Using viper/remote with incompatible versio... — committed to adzeitor/viper by deleted user 5 years ago
- Add test on initialization of viper/remote This test can detect errors with dependencies like #658. — committed to adzeitor/viper by deleted user 5 years ago
- Downgrade ugorji/go/codec from 1.1.2 to 1.1.1 Codec version has been changed in 1.1.2, but current tagged versions of etcd are compatible only with 1.1.1. Using viper/remote with incompatible versio... — committed to adzeitor/viper by deleted user 5 years ago
- Add test on initialization of viper/remote This test can detect errors with dependencies like #658. — committed to adzeitor/viper by deleted user 5 years ago
- Downgrade ugorji/go/codec from 1.1.2 to 1.1.1 Codec version has been changed in 1.1.2, but current tagged versions of etcd are compatible only with 1.1.1. Using viper/remote with incompatible versio... — committed to adzeitor/viper by deleted user 5 years ago
The solution in https://github.com/gin-gonic/gin/issues/1897 may help you.
I think the ultimate fix for this is to remove viper’s indirect dependency on
github.com/ugorji/go/codec(or to switch it togithub.com/ugorji/go).I did
rm github.com/coreos/etcd/client/keys.generated.goand solved the problem. The file should be generated auto,so I wonder how it works undergo mod.It is said thatgo-etcdis “DEPRECATED” and we should “use the official Go client”,butxordataexchange/cryptwhich viper use to contect etcd seems have not been updated for a long time.I think it’s the matter.@bep thanks! And @jadekler thanks for the PR!
FWIW, my failing example from several comments back in https://github.com/spf13/viper/issues/658#issuecomment-494448025 now no longer fails complaining about ambiguous import for
github.com/ugorji/go/codecvs.github.com/ugorji/go/codecif I update that example to use the new commitb5bf975e5823for viper in thego.mod:https://play.golang.org/p/i6msmOVvznW
@ugorji that is progress…
(That playground example now fails with a different error compaining about fsnotify, but that is apparently because fsnotify doesn’t support nacl/amd64p32, which means it fails on the playground… but that is actually a good sign for this particular issue, because it got past the
ugorji/go/codecerrors).