Skip to content

Commit

Permalink
feat: Add global object.
Browse files Browse the repository at this point in the history
  • Loading branch information
leoil committed Aug 19, 2023
1 parent 34b255c commit 6b27d77
Show file tree
Hide file tree
Showing 22 changed files with 435 additions and 253 deletions.
6 changes: 1 addition & 5 deletions casdoorsdk/email.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,7 +49,3 @@ func (c *Client) SendEmail(title string, content string, sender string, receiver

return nil
}

func SendEmail(title string, content string, sender string, receivers ...string) error {
return globalClient.SendEmail(title, content, sender, receivers...)
}
19 changes: 19 additions & 0 deletions casdoorsdk/email_global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package casdoorsdk

func SendEmail(title string, content string, sender string, receivers ...string) error {
return globalClient.SendEmail(title, content, sender, receivers...)
}
14 changes: 14 additions & 0 deletions casdoorsdk/enfocer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package casdoorsdk

import (
Expand Down
14 changes: 14 additions & 0 deletions casdoorsdk/enforcer_global.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package casdoorsdk

func GetEnforcers() ([]*Enforcer, error) {
Expand Down
6 changes: 1 addition & 5 deletions casdoorsdk/jwt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,3 @@ func (c *Client) ParseJwtToken(token string) (*Claims, error) {

return nil, err
}

func ParseJwtToken(token string) (*Claims, error) {
return globalClient.ParseJwtToken(token)
}
19 changes: 19 additions & 0 deletions casdoorsdk/jwt_global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package casdoorsdk

func ParseJwtToken(token string) (*Claims, error) {
return globalClient.ParseJwtToken(token)
}
26 changes: 1 addition & 25 deletions casdoorsdk/organization.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,10 +86,6 @@ func (c *Client) GetOrganization(name string) (*Organization, error) {
return organization, nil
}

func GetOrganization(name string) ([]*Organization, error) {
return globalClient.GetOrganizations()
}

func (c *Client) GetOrganizations() ([]*Organization, error) {
queryMap := map[string]string{
"owner": c.OrganizationName,
Expand All @@ -110,10 +106,6 @@ func (c *Client) GetOrganizations() ([]*Organization, error) {
return organizations, nil
}

func GetOrganizations() ([]*Organization, error) {
return globalClient.GetOrganizations()
}

func (c *Client) GetOrganizationNames() ([]*Organization, error) {
queryMap := map[string]string{
"owner": c.OrganizationName,
Expand All @@ -134,10 +126,6 @@ func (c *Client) GetOrganizationNames() ([]*Organization, error) {
return organizationNames, nil
}

func GetOrganizationNames() ([]*Organization, error) {
return globalClient.GetOrganizationNames()
}

func (c *Client) AddOrganization(organization *Organization) (bool, error) {
if organization.Owner == "" {
organization.Owner = "admin"
Expand All @@ -146,10 +134,6 @@ func (c *Client) AddOrganization(organization *Organization) (bool, error) {
return affected, err
}

func AddOrganization(organization *Organization) (bool, error) {
return globalClient.AddOrganization(organization)
}

func (c *Client) DeleteOrganization(name string) (bool, error) {
organization := Organization{
Owner: "admin",
Expand All @@ -160,15 +144,7 @@ func (c *Client) DeleteOrganization(name string) (bool, error) {
return affected, err
}

func DeleteOrganization(name string) (bool, error) {
return globalClient.DeleteOrganization(name)
}

func (c *Client) UpdateOrganization(organization *Organization) (bool, error) {
_, affected, err := c.modifyOrganization("update-organization", organization, nil)
return affected, err
}

func UpdateOrganization(organization *Organization) (bool, error) {
return globalClient.UpdateOrganization(organization)
}
39 changes: 39 additions & 0 deletions casdoorsdk/organization_global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package casdoorsdk

func GetOrganization(name string) ([]*Organization, error) {
return globalClient.GetOrganizations()
}

func GetOrganizations() ([]*Organization, error) {
return globalClient.GetOrganizations()
}

func GetOrganizationNames() ([]*Organization, error) {
return globalClient.GetOrganizationNames()
}

func AddOrganization(organization *Organization) (bool, error) {
return globalClient.AddOrganization(organization)
}

func DeleteOrganization(name string) (bool, error) {
return globalClient.DeleteOrganization(name)
}

func UpdateOrganization(organization *Organization) (bool, error) {
return globalClient.UpdateOrganization(organization)
}
30 changes: 1 addition & 29 deletions casdoorsdk/resource.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,18 +61,10 @@ func (c *Client) GetResource(id string) (*Resource, error) {
return resource, nil
}

func GetResource(id string) (*Resource, error) {
return globalClient.GetResource(id)
}

func (c *Client) GetResourceEx(owner, name string) (*Resource, error) {
return c.GetResource(fmt.Sprintf("%s/%s", owner, name))
}

func GetResourceEx(owner, name string) (*Resource, error) {
return globalClient.GetResourceEx(owner, name)
}

func (c *Client) GetResources(owner, user, field, value, sortField, sortOrder string) ([]*Resource, error) {
queryMap := map[string]string{
"owner": owner,
Expand All @@ -98,10 +90,6 @@ func (c *Client) GetResources(owner, user, field, value, sortField, sortOrder st
return resources, nil
}

func GetResources(owner, user, field, value, sortField, sortOrder string) ([]*Resource, error) {
return globalClient.GetResources(owner, user, field, value, sortField, sortOrder)
}

func (c *Client) GetPaginationResources(owner, user, field, value string, pageSize, page int, sortField, sortOrder string) ([]*Resource, error) {
queryMap := map[string]string{
"owner": owner,
Expand Down Expand Up @@ -129,10 +117,6 @@ func (c *Client) GetPaginationResources(owner, user, field, value string, pageSi
return resources, nil
}

func GetPaginationResources(owner, user, field, value string, pageSize, page int, sortField, sortOrder string) ([]*Resource, error) {
return globalClient.GetPaginationResources(owner, user, field, value, pageSize, page, sortField, sortOrder)
}

func (c *Client) UploadResource(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, string, error) {
queryMap := map[string]string{
"owner": c.OrganizationName,
Expand All @@ -157,10 +141,6 @@ func (c *Client) UploadResource(user string, tag string, parent string, fullFile
return fileUrl, name, nil
}

func UploadResource(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, string, error) {
return globalClient.UploadResource(user, tag, parent, fullFilePath, fileBytes)
}

func (c *Client) UploadResourceEx(user string, tag string, parent string, fullFilePath string, fileBytes []byte, createdTime string, description string) (string, string, error) {
queryMap := map[string]string{
"owner": c.OrganizationName,
Expand All @@ -187,10 +167,6 @@ func (c *Client) UploadResourceEx(user string, tag string, parent string, fullFi
return fileUrl, name, nil
}

func UploadResourceEx(user string, tag string, parent string, fullFilePath string, fileBytes []byte, createdTime string, description string) (string, string, error) {
return globalClient.UploadResourceEx(user, tag, parent, fullFilePath, fileBytes, createdTime, description)
}

func (c *Client) DeleteResource(name string) (bool, error) {
resource := Resource{
Owner: c.OrganizationName,
Expand All @@ -208,7 +184,3 @@ func (c *Client) DeleteResource(name string) (bool, error) {

return resp.Data == "Affected", nil
}

func DeleteResource(name string) (bool, error) {
return globalClient.DeleteResource(name)
}
43 changes: 43 additions & 0 deletions casdoorsdk/resource_global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package casdoorsdk

func GetResource(id string) (*Resource, error) {
return globalClient.GetResource(id)
}

func GetResourceEx(owner, name string) (*Resource, error) {
return globalClient.GetResourceEx(owner, name)
}

func GetResources(owner, user, field, value, sortField, sortOrder string) ([]*Resource, error) {
return globalClient.GetResources(owner, user, field, value, sortField, sortOrder)
}

func GetPaginationResources(owner, user, field, value string, pageSize, page int, sortField, sortOrder string) ([]*Resource, error) {
return globalClient.GetPaginationResources(owner, user, field, value, pageSize, page, sortField, sortOrder)
}

func UploadResource(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, string, error) {
return globalClient.UploadResource(user, tag, parent, fullFilePath, fileBytes)
}

func UploadResourceEx(user string, tag string, parent string, fullFilePath string, fileBytes []byte, createdTime string, description string) (string, string, error) {
return globalClient.UploadResourceEx(user, tag, parent, fullFilePath, fileBytes, createdTime, description)
}

func DeleteResource(name string) (bool, error) {
return globalClient.DeleteResource(name)
}
Loading

0 comments on commit 6b27d77

Please sign in to comment.