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

Most upvoted comments

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 to github.com/ugorji/go).

I did rm github.com/coreos/etcd/client/keys.generated.go and solved the problem. The file should be generated auto,so I wonder how it works under go mod.It is said that go-etcd is “DEPRECATED” and we should “use the official Go client”,but xordataexchange/crypt which 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/codec vs. github.com/ugorji/go/codec if I update that example to use the new commit b5bf975e5823 for viper in the go.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/codec errors).