Skip to content

Commit cfda87d

Browse files
committed
refactor: queryparams map fn
1 parent 47bb62a commit cfda87d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

internal/sdk/cloudian/qos.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ func (qos *QualityOfService) unmarshalQOSList(raw []byte) error {
7070
return nil
7171
}
7272

73-
// CreateQuota sets the QoS limits for a `User`. To change QoS limits, a delete and recreate is necessary.
74-
func (client Client) CreateQuota(ctx context.Context, user User, qos QualityOfService) error {
73+
func (qos QualityOfService) queryParams() (map[string]string, error) {
7574
rawParams := map[string]*int64{
7675
"hlStorageQuotaKBytes": qos.Hard.StorageQuotaKiBs,
7776
"wlStorageQuotaKBytes": qos.Warning.StorageQuotaKiBs,
@@ -92,10 +91,19 @@ func (client Client) CreateQuota(ctx context.Context, user User, qos QualityOfSe
9291
val = *raw
9392
}
9493
if val < -1 {
95-
return fmt.Errorf("invalid QoS limit value: %d", val)
94+
return nil, fmt.Errorf("invalid QoS limit value: %d", val)
9695
}
9796
params[key] = strconv.FormatInt(val, 10)
9897
}
98+
return params, nil
99+
}
100+
101+
// CreateQuota sets the QoS limits for a `User`. To change QoS limits, a delete and recreate is necessary.
102+
func (client Client) CreateQuota(ctx context.Context, user User, qos QualityOfService) error {
103+
params, err := qos.queryParams()
104+
if err != nil {
105+
return err
106+
}
99107

100108
resp, err := client.newRequest(ctx).
101109
SetQueryParam("userId", user.UserID).

0 commit comments

Comments
 (0)