Categorygithub.com/batchcorp/etcd-watcher
modulepackage
2.0.3-batch+incompatible
Repository: https://github.com/batchcorp/etcd-watcher.git
Documentation: pkg.go.dev

# README

Etcd Watcher Go Coverage Status Godoc

UPDATE 01/04/2022

We needed to create this fork in order to get around some internal go mod issues; while at it, we also added TLS support.


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

Installation

go get github.com/batchcorp/etcd-watcher/v2

Simple Example

package main

import (
    "log"

    casbin "github.com/batchcorp/casbin/v2"
    etcdwatcher "github.com/batchcorp/etcd-watcher/v2"
)

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{"http://127.0.0.1:2379"}, "keyname", nil)
    
    // Initialize the enforcer.
    e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
    
    // Set the watcher for the enforcer.
    e.SetWatcher(w)
    
    // 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.
    w.SetUpdateCallback(updateCallback)
    
    // Update the policy to test the effect.
    // You should see "[New revision detected: X]" in the log.
    e.SavePolicy()
}

Getting Help

License

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

# Functions

NewWatcher is the constructor for Watcher.

# Structs

No description provided by the author
No description provided by the author