update readme and add travis.yml
4 files changed
tree: 19f5bb152372129aded60196a10cc136b34323dc
  1. example/
  2. .gitignore
  3. .travis.yml
  4. get_perm_api.go
  5. get_perm_api_test.go
  6. go.mod
  7. go.sum
  8. README.md
README.md

Casbin.js Server Utilities for Casbin

If you are using Casbin.js at your frontend and Go Casbinas your backend Casbin service, you can install this package at your backend. This package provides a wrapper for generating the user permission, which can be passed to Casbin.js at the frontend.

Installation

go get github.com/casbin-js/go-utils/v2

Example

package main

import (
    "fmt"

    casbinjs "github.com/casbin-js/go-utils"
    "github.com/casbin/casbin"
)

func main() {
    e, err := casbin.NewEnforcer("path/to/model.conf", "path/to/policy.csv")
    if err != nil {
        panic(err)
    }
    s, _ := casbinjs.GetPermissionForUser(e, "alice")
    // Now `s` has the info of alice's permission
    // Pass the permission data to your frontend application.
}