control: make Consul opt more explicit

This commit is contained in:
Gyu-Ho Lee 2016-11-15 19:05:14 -08:00
parent 5cb2b9c74d
commit c6e00f4637
No known key found for this signature in database
GPG Key ID: 1DDD39C7EB70C24C
1 changed files with 5 additions and 2 deletions

View File

@ -107,10 +107,13 @@ func newGetZK(conn *zk.Conn) ReqHandler {
func newGetConsul(conn *consulapi.KV) ReqHandler { func newGetConsul(conn *consulapi.KV) ReqHandler {
return func(ctx context.Context, req *request) error { return func(ctx context.Context, req *request) error {
opt := &consulapi.QueryOptions{ opt := &consulapi.QueryOptions{}
AllowStale: req.consulOp.staleRead, if req.consulOp.staleRead {
opt.AllowStale = true
opt.RequireConsistent = false
} }
if !req.consulOp.staleRead { if !req.consulOp.staleRead {
opt.AllowStale = false
opt.RequireConsistent = true opt.RequireConsistent = true
} }
_, _, err := conn.Get(req.consulOp.key, opt) _, _, err := conn.Get(req.consulOp.key, opt)