Consul golang api for watch

1,747 views
Skip to first unread message

Keshava Bharadwaj

unread,
Nov 9, 2016, 4:24:08 AM11/9/16
to Consul
Hi,

I went through the consul api documentation to check for an api to do watch on a kv, and could not find one.
I had used node client earlier and its like this - https://github.com/silas/node-consul#watch

Is the 'Watch" api not available? or am i missing something?

- Keshava

James Phillips

unread,
Dec 19, 2016, 6:18:25 PM12/19/16
to consu...@googlegroups.com
Hi,

We could improve the documentation a bit around this, but watches are
definitely possible with the API. The basic workflow is that you do an
initial query, and then set the WaitIndex of your QueryOptions to that
index to block until things change. You can see an example here:

https://github.com/hashicorp/consul/blob/master/api/lock.go#L357-L384

And Consul's watches are implemented in terms of the API package as
well, you can see those here:

https://github.com/hashicorp/consul/blob/master/watch/funcs.go

-- James
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/consul/issues
> IRC: #consul on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Consul" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to consul-tool...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/consul-tool/2c131559-8e3a-4ae5-9fc4-9cf59893ded2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages