Skip to content

Commit

Permalink
feat: fix all GetPagination methods error: "response data format is i…
Browse files Browse the repository at this point in the history
…ncorrect" (#117)
  • Loading branch information
Daniil Pershin authored Jul 3, 2024
1 parent 471f21b commit 0b220df
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 44 deletions.
10 changes: 8 additions & 2 deletions casdoorsdk/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ func (c *Client) GetPaginationAdapters(p int, pageSize int, queryMap map[string]
return nil, 0, err
}

adapters, ok := response.Data.([]*Adapter)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var adapters []*Adapter
err = json.Unmarshal(dataBytes, &adapters)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ func (c *Client) GetPaginationEnforcers(p int, pageSize int, queryMap map[string
return nil, 0, err
}

enforcers, ok := response.Data.([]*Enforcer)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var enforcers []*Enforcer
err = json.Unmarshal(dataBytes, &enforcers)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
24 changes: 15 additions & 9 deletions casdoorsdk/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ type Group struct {
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"`

DisplayName string `xorm:"varchar(100)" json:"displayName"`
Manager string `xorm:"varchar(100)" json:"manager"`
ContactEmail string `xorm:"varchar(100)" json:"contactEmail"`
Type string `xorm:"varchar(100)" json:"type"`
ParentId string `xorm:"varchar(100)" json:"parentId"`
IsTopGroup bool `xorm:"bool" json:"isTopGroup"`
Users []*User `xorm:"-" json:"users"`
DisplayName string `xorm:"varchar(100)" json:"displayName"`
Manager string `xorm:"varchar(100)" json:"manager"`
ContactEmail string `xorm:"varchar(100)" json:"contactEmail"`
Type string `xorm:"varchar(100)" json:"type"`
ParentId string `xorm:"varchar(100)" json:"parentId"`
IsTopGroup bool `xorm:"bool" json:"isTopGroup"`
Users []string `xorm:"mediumtext" json:"users"`

Title string `json:"title,omitempty"`
Key string `json:"key,omitempty"`
Expand Down Expand Up @@ -74,8 +74,14 @@ func (c *Client) GetPaginationGroups(p int, pageSize int, queryMap map[string]st
return nil, 0, err
}

groups, ok := response.Data.([]*Group)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var groups []*Group
err = json.Unmarshal(dataBytes, &groups)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
12 changes: 9 additions & 3 deletions casdoorsdk/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Model struct {
Children []*Model `json:"children,omitempty"`

ModelText string `xorm:"mediumtext" json:"modelText"`
IsEnabled bool `json:"isEnabled"`
IsEnabled bool `json:"isEnabled"`
}

func (c *Client) GetModels() ([]*Model, error) {
Expand Down Expand Up @@ -75,8 +75,14 @@ func (c *Client) GetPaginationModels(p int, pageSize int, queryMap map[string]st
return nil, 0, err
}

models, ok := response.Data.([]*Model)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var models []*Model
err = json.Unmarshal(dataBytes, &models)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ func (c *Client) GetPaginationPayments(p int, pageSize int, queryMap map[string]
return nil, 0, err
}

payments, ok := response.Data.([]*Payment)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var payments []*Payment
err = json.Unmarshal(dataBytes, &payments)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ func (c *Client) GetPaginationPermissions(p int, pageSize int, queryMap map[stri
return nil, 0, err
}

permissions, ok := response.Data.([]*Permission)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var permissions []*Permission
err = json.Unmarshal(dataBytes, &permissions)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ func (c *Client) GetPaginationPlans(p int, pageSize int, queryMap map[string]str
return nil, 0, err
}

plans, ok := response.Data.([]*Plan)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var plans []*Plan
err = json.Unmarshal(dataBytes, &plans)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ func (c *Client) GetPaginationPricings(p int, pageSize int, queryMap map[string]
return nil, 0, err
}

pricings, ok := response.Data.([]*Pricing)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var pricings []*Pricing
err = json.Unmarshal(dataBytes, &pricings)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ func (c *Client) GetPaginationProducts(p int, pageSize int, queryMap map[string]
return nil, 0, err
}

products, ok := response.Data.([]*Product)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var products []*Product
err = json.Unmarshal(dataBytes, &products)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
12 changes: 10 additions & 2 deletions casdoorsdk/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ func (c *Client) GetPaginationProviders(p int, pageSize int, queryMap map[string
if err != nil {
return nil, 0, err
}
providers, ok := response.Data.([]*Provider)
if !ok {

dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var providers []*Provider
err = json.Unmarshal(dataBytes, &providers)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

return providers, int(response.Data2.(float64)), nil
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ func (c *Client) GetPaginationRecords(p int, pageSize int, queryMap map[string]s
return nil, 0, err
}

records, ok := response.Data.([]*Record)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var records []*Record
err = json.Unmarshal(dataBytes, &records)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
11 changes: 9 additions & 2 deletions casdoorsdk/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ func (c *Client) GetPaginationRoles(p int, pageSize int, queryMap map[string]str
return nil, 0, err
}

roles, ok := response.Data.([]*Role)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var roles []*Role
err = json.Unmarshal(dataBytes, &roles)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

return roles, int(response.Data2.(float64)), nil
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ func (c *Client) GetPaginationSessions(p int, pageSize int, queryMap map[string]
return nil, 0, err
}

sessions, ok := response.Data.([]*Session)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var sessions []*Session
err = json.Unmarshal(dataBytes, &sessions)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}
return sessions, int(response.Data2.(float64)), nil
Expand Down
12 changes: 10 additions & 2 deletions casdoorsdk/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ func (c *Client) GetPaginationSubscriptions(p int, pageSize int, queryMap map[st
if err != nil {
return nil, 0, err
}
subscriptions, ok := response.Data.([]*Subscription)
if !ok {

dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var subscriptions []*Subscription
err = json.Unmarshal(dataBytes, &subscriptions)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

return subscriptions, int(response.Data2.(float64)), nil
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ func (c *Client) GetPaginationSyncers(p int, pageSize int, queryMap map[string]s
return nil, 0, err
}

syncers, ok := response.Data.([]*Syncer)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var syncers []*Syncer
err = json.Unmarshal(dataBytes, &syncers)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ func (c *Client) GetPaginationTokens(p int, pageSize int, queryMap map[string]st
return nil, 0, err
}

tokens, ok := response.Data.([]*Token)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var tokens []*Token
err = json.Unmarshal(dataBytes, &tokens)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ func (c *Client) GetPaginationTransactions(p int, pageSize int, queryMap map[str
return nil, 0, err
}

transactions, ok := response.Data.([]*Transaction)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var transactions []*Transaction
err = json.Unmarshal(dataBytes, &transactions)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down
10 changes: 8 additions & 2 deletions casdoorsdk/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ func (c *Client) GetPaginationWebhooks(p int, pageSize int, queryMap map[string]
return nil, 0, err
}

webhooks, ok := response.Data.([]*Webhook)
if !ok {
dataBytes, err := json.Marshal(response.Data)
if err != nil {
return nil, 0, err
}

var webhooks []*Webhook
err = json.Unmarshal(dataBytes, &webhooks)
if err != nil {
return nil, 0, errors.New("response data format is incorrect")
}

Expand Down

0 comments on commit 0b220df

Please sign in to comment.