Skip to content

Commit 17364bc

Browse files
committed
fix: lint
1 parent dfd4d79 commit 17364bc

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

internal/sdk/cloudian/qos.go

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,51 @@ type QualityOfServiceLimits struct {
2929
OutboundKiBsPerMin *int64
3030
}
3131

32+
// nolint: gocyclo
33+
func (qos *QualityOfService) unmarshalJSON(raw []byte) error {
34+
var data struct {
35+
QOSLimitList []struct {
36+
Type string `json:"type"`
37+
Value int64 `json:"value"`
38+
} `json:"qosLimitList"`
39+
}
40+
41+
if err := json.Unmarshal(raw, &data); err != nil {
42+
return err
43+
}
44+
45+
for _, item := range data.QOSLimitList {
46+
if item.Value < 0 {
47+
continue
48+
}
49+
50+
v := &item.Value
51+
switch item.Type {
52+
case "STORAGE_QUOTA_KBYTES_LH":
53+
qos.Hard.StorageQuotaKiBs = v
54+
case "STORAGE_QUOTA_KBYTES_LW":
55+
qos.Soft.StorageQuotaKiBs = v
56+
case "STORAGE_QUOTA_COUNT_LH":
57+
qos.Hard.StorageQuotaCount = v
58+
case "STORAGE_QUOTA_COUNT_LW":
59+
qos.Soft.StorageQuotaCount = v
60+
case "REQUEST_RATE_LH":
61+
qos.Hard.RequestsPerMin = v
62+
case "REQUEST_RATE_LW":
63+
qos.Soft.RequestsPerMin = v
64+
case "DATAKBYTES_IN_LH":
65+
qos.Hard.InboundKiBsPerMin = v
66+
case "DATAKBYTES_IN_LW":
67+
qos.Soft.InboundKiBsPerMin = v
68+
case "DATAKBYTES_OUT_LH":
69+
qos.Hard.OutboundKiBsPerMin = v
70+
case "DATAKBYTES_OUT_LW":
71+
qos.Soft.OutboundKiBsPerMin = v
72+
}
73+
}
74+
return nil
75+
}
76+
3277
// CreateQuota sets the QoS limits for a `User`. To change QoS limits, a delete and recreate is necessary.
3378
func (client Client) CreateQuota(ctx context.Context, user User, qos QualityOfService) error {
3479
rawParams := map[string]*int64{
@@ -84,48 +129,8 @@ func (client Client) GetQuota(ctx context.Context, user User) (*QualityOfService
84129

85130
switch resp.StatusCode() {
86131
case 200:
87-
var data struct {
88-
QOSLimitList []struct {
89-
Type string
90-
Value int64
91-
} `json:"qosLimitList"`
92-
}
93-
94-
if err := json.Unmarshal(resp.Body(), &data); err != nil {
95-
return nil, err
96-
}
97-
98132
qos := QualityOfService{}
99-
for _, item := range data.QOSLimitList {
100-
if item.Value < 0 {
101-
continue
102-
}
103-
104-
v := &item.Value
105-
switch item.Type {
106-
case "STORAGE_QUOTA_KBYTES_LH":
107-
qos.Hard.StorageQuotaKiBs = v
108-
case "STORAGE_QUOTA_KBYTES_LW":
109-
qos.Soft.StorageQuotaKiBs = v
110-
case "STORAGE_QUOTA_COUNT_LH":
111-
qos.Hard.StorageQuotaCount = v
112-
case "STORAGE_QUOTA_COUNT_LW":
113-
qos.Soft.StorageQuotaCount = v
114-
case "REQUEST_RATE_LH":
115-
qos.Hard.RequestsPerMin = v
116-
case "REQUEST_RATE_LW":
117-
qos.Soft.RequestsPerMin = v
118-
case "DATAKBYTES_IN_LH":
119-
qos.Hard.InboundKiBsPerMin = v
120-
case "DATAKBYTES_IN_LW":
121-
qos.Soft.InboundKiBsPerMin = v
122-
case "DATAKBYTES_OUT_LH":
123-
qos.Hard.OutboundKiBsPerMin = v
124-
case "DATAKBYTES_OUT_LW":
125-
qos.Soft.OutboundKiBsPerMin = v
126-
}
127-
}
128-
return &qos, nil
133+
return &qos, qos.unmarshalJSON(resp.Body())
129134
default:
130135
return nil, fmt.Errorf("SET quota unexpected status: %d", resp.StatusCode())
131136
}

0 commit comments

Comments
 (0)