Skip to content

grepsr/casbin-zk-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

casbin-zk-watcher

casbin-zk-watcher is the Apache Zookeeper watcher for Casbin.

Installation

go get -u github.com/grepsr/casbin-zk-watcher

Example

package main

import (
    "github.com/casbin/casbin"
    "github.com/casbin/casbin/util"
    "github.com/grepsr/casbin-zk-watcher"
)

func updateCallback(rev string) {
    util.LogPrint("New revision detected:", rev)
}

func main() {
    // Initialize the watcher.
    // hosts can be either a single URL or a comma-separated list of URLs to zookeeper hosts.
    // path is the path which will be watched. If not provided, it defaults to "/casbin".
    w := zkwatcher.NewWatcher("<hosts>", "<path>")
    
    // 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()
}

Requirements

About

Zookeeper watcher for casbin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages