acl.go 621 B

12345678910111213141516171819202122232425262728293031
  1. package acl
  2. import (
  3. "sync"
  4. "fmt"
  5. )
  6. var AclList = &sync.Map{}
  7. func AddMemberPermission(account string,resource Resource) {
  8. key := account + "!" + resource.Code
  9. AclList.Store(key,resource)
  10. }
  11. //判断指定的资源是否可以访问
  12. func IsAllow(account ,controllerName,actionName,methodName string) bool {
  13. key := fmt.Sprintf("%s!%s!%s!%s",account,controllerName,actionName,methodName)
  14. fmt.Println(key)
  15. if _,ok := AclList.Load(key);ok {
  16. return true
  17. }
  18. key = fmt.Sprintf("%s!%s!%s!*",account,controllerName,actionName)
  19. fmt.Println(key)
  20. if _,ok := AclList.Load(key);ok {
  21. return true
  22. }
  23. return false
  24. }