You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

resource_adaptor.go 976 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package casdoor
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego"
  5. "github.com/casbin/casibase/util"
  6. "github.com/casdoor/casdoor-go-sdk/casdoorsdk"
  7. )
  8. func ListResources(prefix string) ([]*casdoorsdk.Resource, error) {
  9. prefix = util.GetIdFromOwnerAndName(fmt.Sprintf("/resource/%s/%s/casibase",
  10. beego.AppConfig.String("casdoorOrganization"),
  11. beego.AppConfig.String("casdoorApplication")), prefix)
  12. result := make([]*casdoorsdk.Resource, 0)
  13. err := adapter.Engine.Where("name like ?", prefix+"%").Find(&result)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return result, nil
  18. }
  19. func GetResource(key string) (*casdoorsdk.Resource, error) {
  20. id := fmt.Sprintf("/resource/%s/%s/casibase/%s", Organization, Application, key)
  21. resource := casdoorsdk.Resource{Owner: Organization, Name: id}
  22. existed, err := adapter.Engine.Get(&resource)
  23. if err != nil {
  24. return nil, err
  25. }
  26. if existed {
  27. return &resource, nil
  28. } else {
  29. return nil, fmt.Errorf("resource %s not found", key)
  30. }
  31. }