TiKV watcher for Casbin

Clone this repo:
  1. 65ed052 Fix README. by Yang Luo · 4 years, 9 months ago master
  2. a0094b6 Merge pull request #4 from ComradeProgrammer/master by Yang Luo · 4 years, 9 months ago
  3. 6bcecfc feat: Update README.md and add badges by Товарищ программист · 4 years, 9 months ago
  4. 21c5859 Fix typo. by Yang Luo · 4 years, 9 months ago
  5. 70a09cf Merge pull request #2 from ComradeProgrammer/tikv_watcher by Yang Luo · 4 years, 9 months ago

TiKV Watcher

Go Go Report Card Go Reference

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

Note: Considering that TiKV doesn't have watch mechanism like etcd or channel like Redis, this ugly implementation uses polling to achieve monitoring a certain key, which may cause some performance trouble

Installation:

go get github.com/casbin/tikv-watcher

Single Example:

start the TiKV service before run this example:

package main

import (
	"fmt"
	"time"

	watcher "github.com/casbin/tikv-watcher"
	casbin "github.com/casbin/casbin/v2"
)

func main() {
	e, _ := casbin.NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
	w, err := watcher.NewWatcher(
		"testkey",
		100*time.Millisecond,
		"127.0.0.1:2379",
	)
	if err != nil {
		panic(err)
		return
	}
	e.SetWatcher(w)
	w.SetUpdateCallback(
		func(s string) {
			fmt.Println("===================get" + s)
		},
	)
	e.SavePolicy()
	time.Sleep(10 * time.Second)

}


License:

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