Awesome Open Source
Awesome Open Source

Etcd Watcher Go Coverage Status Godoc

Etcd Watcher is the Etcd watcher for Casbin. With this library, Casbin can synchronize the policy with the database in multiple enforcer instances.


go get

Simple Example

package main

import (

    casbin ""
    etcdwatcher ""

func updateCallback(rev string) {
    log.Println("New revision detected:", rev)

func main() {
    // Initialize the watcher.
    // Use the endpoint of etcd cluster as parameter.
    w, _ := etcdwatcher.NewWatcher([]string{""}, "keyname")
    // Initialize the enforcer.
    e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
    // Set the watcher for the enforcer.
    // By default, the watcher's callback is automatically set to the
    // enforcer's LoadPolicy() in the SetWatcher() call.
    // We can change it by explicitly setting a callback.
    // Update the policy to test the effect.
    // You should see "[New revision detected: X]" in the log.

Getting Help


This project is under Apache 2.0 License. See the LICENSE file for the full license text.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Go (198,300
Authorization (1,338
Access Control (398
Etcd (375
Watcher (221
Casbin (193
Related Projects