The latest ristretto update seems to install some flags into the go stdlib flags namespace, seemingly via a dependency. Here is a minimal repro (also at The Go Playground):
package main
import (
"flag"
"github.com/dgraph-io/ristretto"
)
func main() {
var verbose bool
flag.BoolVar(&verbose, "v", false, "Verbose")
flag.Parse()
var _ *ristretto.Cache
}
Here is the error:
/tmpfs/play flag redefined: v
panic: /tmpfs/play flag redefined: v
goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000ba120, 0x52d3c8, 0xc0000b60d0, 0x507c45, 0x1, 0x50834d, 0x7)
/usr/local/go-faketime/src/flag/flag.go:871 +0x485
flag.BoolVar(...)
/usr/local/go-faketime/src/flag/flag.go:636
main.main()
/tmp/sandbox757184837/prog.go:11 +0x85
I would expect the above code to compile and run without error.
Hi! I have also stumbled upon this problem when using dbadger. Seems to be introduced by glog:
Polluting flags in a logging package only makes sense for the purpose of uniformity inside Google, which is the purpose of glog in the first place as stated in a public repo. Not sure why it is used here…
The workaround is not to use default flag set of flag package:
package main
import (
"flag"
"os"
"github.com/dgraph-io/ristretto"
)
func main() {
var verbose bool
flag := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
flag.BoolVar(&verbose, "v", false, "Verbose")
_ = flag.Parse(os.Args[1:]) // Ignore error as we flag.ExitOnError
var _ *ristretto.Cache
}