Use json format for argString in RunCasbinCommand()

This commit is contained in:
Yang Luo
2024-11-15 18:27:25 +08:00
parent 7ccd8c4d4f
commit 5cbd0a96ca

View File

@ -15,9 +15,9 @@
package controllers
import (
"encoding/json"
"fmt"
"os/exec"
"strings"
)
// RunCasbinCommand
@ -44,9 +44,14 @@ func (c *ApiController) RunCasbinCommand() {
}
// argString's example:
// enforce -m "examples/rbac_model.conf" -p "examples/rbac_policy.csv" "alice" "data1" "read"
// ["enforce", "-m", "examples/rbac_model.conf", "-p", "examples/rbac_policy.csv", "alice", "data1", "read"]
// see: https://github.com/jcasbin/casbin-java-cli?tab=readme-ov-file#get-started
args := strings.Split(argString, " ")
var args []string
err = json.Unmarshal([]byte(argString), &args)
if err != nil {
c.ResponseError(err.Error())
return
}
command := exec.Command(binaryName, args...)
outputBytes, err := command.CombinedOutput()