diff --git a/README.md b/README.md index 1a0b4d4..1a29928 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ And **go-api-gateway** provide the **swagger.json** at path **/gateway/swagger/* Because of initialization data into **casbin_rule** table ```bash -p admin /policy/* (GET)|(POST)|(PUT)|(DELETE) +p admin /policy/* (GET)|(POST)|(PUT)|(DELETE)|(HEAD) ``` So register **admin** first to authorize the operation at **/gateway/docs/** diff --git a/enforcer/casbin.go b/enforcer/casbin.go index 077ad31..7d2f663 100644 --- a/enforcer/casbin.go +++ b/enforcer/casbin.go @@ -58,8 +58,8 @@ func insertData(dataSourceName string) (err error) { return err } defer engine.Close() - engine.Exec("DELETE FROM `"+dbName+"`.`casbin_rule` WHERE `p_type`='p' AND `v0`='admin' AND `v1`='/policy/*' AND `v2`='(GET)|(POST)|(PUT)|(DELETE)' AND `v3`IS NULL AND `v4`IS NULL AND `v5`IS NULL") - _, err = engine.Exec("INSERT INTO `"+dbName+"`.`casbin_rule`(`p_type`,`v0`,`v1`,`v2`) VALUES ('p','admin','/policy/*','(GET)|(POST)|(PUT)|(DELETE)')") + engine.Exec("DELETE FROM `"+dbName+"`.`casbin_rule` WHERE `p_type`='p' AND `v0`='admin' AND `v1`='/policy/*' AND `v2`='(GET)|(POST)|(PUT)|(DELETE)|(HEAD)' AND `v3`IS NULL AND `v4`IS NULL AND `v5`IS NULL") + _, err = engine.Exec("INSERT INTO `"+dbName+"`.`casbin_rule`(`p_type`,`v0`,`v1`,`v2`) VALUES ('p','admin','/policy/*','(GET)|(POST)|(PUT)|(DELETE)|(HEAD)')") }else { err=fmt.Errorf("dataSourceName:%s doesn't exist dbName",dataSourceName) }