Code Monkey home page Code Monkey logo

Comments (4)

 avatar commented on August 19, 2024

Here is my go.mod:

go 1.16

require (
github.com/EntropyPool/entropy-logger v0.0.0-20210320022718-3091537e035f
github.com/NpoolRD/http-daemon v0.0.0-20210505073728-a1d91b8af9df
github.com/casbin/casbin v1.9.1
github.com/casbin/casbin/v2 v2.36.1
github.com/casbin/xorm-adapter/v2 v2.3.2
github.com/go-sql-driver/mysql v1.6.0
github.com/urfave/cli/v2 v2.3.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
)

from xorm-adapter.

 avatar commented on August 19, 2024

here is my code:

a, err := xormadapter.NewAdapter("mysql", "root:123456@tcp(172.17.0.2:3306)/casbin", true)
	if err != nil {
		log.Fatalf("error: adapter: %s", err)
	}

	m, err := model.NewModelFromString(`
	[request_definition]
	r = sub, obj, act
	
	[policy_definition]
	p = sub, obj, act
	
	[role_definition]
	g = _, _
	
	[policy_effect]
	e = some(where (p.eft == allow))
	
	[matchers]
	m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act 
`)
	if err != nil {
		log.Fatalf("error: model: %s", err)
	}

	e, err := casbin.NewEnforcer(m, a)
	if err != nil {
		log.Fatalf("error: enforcer: %s", err)
	}

	updated, err := e.UpdateGroupingPolicy([]string{"zpl", "admin"}, []string{"zpl", "person"})
	if err != nil {
		fmt.Println("update err is:", err)
		return
	}
	if updated {
		fmt.Println("updated")
	} else {
		fmt.Println("not updated")
	}

from xorm-adapter.

hsluoyz avatar hsluoyz commented on August 19, 2024

@closetool @tangyang9464

from xorm-adapter.

github-actions avatar github-actions commented on August 19, 2024

🎉 This issue has been resolved in version 2.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

from xorm-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.