Skip to content

Commit

Permalink
update api-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
bachue committed Oct 27, 2024
1 parent 97a8837 commit d952090
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api-specs
Submodule api-specs updated 1 files
+43 −0 iam/modify_group.yml
8 changes: 4 additions & 4 deletions iam/apis/api_modify_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (iam *Iam) ModifyGroup(ctx context.Context, request *ModifyGroupRequest, op
if err != nil {
return nil, err
}
req := httpclient.Request{Method: "PATCH", ServiceNames: serviceNames, Path: path, RawQuery: rawQuery, Endpoints: options.OverwrittenEndpoints, Region: options.OverwrittenRegion, Interceptors: []httpclient.Interceptor{uplogInterceptor}, AuthType: auth.TokenQiniu, Credentials: innerRequest.Credentials, RequestBody: body, OnRequestProgress: options.OnRequestProgress}
req := httpclient.Request{Method: "PATCH", ServiceNames: serviceNames, Path: path, RawQuery: rawQuery, Endpoints: options.OverwrittenEndpoints, Region: options.OverwrittenRegion, Interceptors: []httpclient.Interceptor{uplogInterceptor}, AuthType: auth.TokenQiniu, Credentials: innerRequest.Credentials, BufferResponse: true, RequestBody: body, OnRequestProgress: options.OnRequestProgress}
if options.OverwrittenEndpoints == nil && options.OverwrittenRegion == nil && iam.client.GetRegions() == nil {
bucketHosts := httpclient.DefaultBucketHosts()

Expand All @@ -99,9 +99,9 @@ func (iam *Iam) ModifyGroup(ctx context.Context, request *ModifyGroupRequest, op
}
}
}
resp, err := iam.client.Do(ctx, &req)
if err != nil {
var respBody ModifyGroupResponse
if err := iam.client.DoAndAcceptJSON(ctx, &req, &respBody); err != nil {
return nil, err
}
return &ModifyGroupResponse{}, resp.Body.Close()
return &respBody, nil
}
97 changes: 96 additions & 1 deletion iam/apis/modify_group/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package modify_group
import (
"encoding/json"
credentials "github.com/qiniu/go-sdk/v7/storagev2/credentials"
errors "github.com/qiniu/go-sdk/v7/storagev2/errors"
)

// 调用 API 所用的请求
Expand Down Expand Up @@ -43,4 +44,98 @@ func (j *Request) validate() error {
}

// 获取 API 所用的响应
type Response struct{}
type Response struct {
Data ModifyGroupData // 用户分组信息
}

// 用户分组信息
type Data struct {
Id string // 记录 ID
RootUid int64 // 根用户 uid
Alias string // 用户分组别名
Description string // 用户分组描述
Enabled bool // 用户分组是否启用
CreatedAt string // 用户分组创建时间
UpdatedAt string // 用户分组上次更新时间
}

// 返回的用户分组信息
type ModifyGroupData = Data
type jsonData struct {
Id string `json:"id"` // 记录 ID
RootUid int64 `json:"root_uid"` // 根用户 uid
Alias string `json:"alias"` // 用户分组别名
Description string `json:"description"` // 用户分组描述
Enabled bool `json:"enabled"` // 用户分组是否启用
CreatedAt string `json:"created_at"` // 用户分组创建时间
UpdatedAt string `json:"updated_at"` // 用户分组上次更新时间
}

func (j *Data) MarshalJSON() ([]byte, error) {
if err := j.validate(); err != nil {
return nil, err
}
return json.Marshal(&jsonData{Id: j.Id, RootUid: j.RootUid, Alias: j.Alias, Description: j.Description, Enabled: j.Enabled, CreatedAt: j.CreatedAt, UpdatedAt: j.UpdatedAt})
}
func (j *Data) UnmarshalJSON(data []byte) error {
var nj jsonData
if err := json.Unmarshal(data, &nj); err != nil {
return err
}
j.Id = nj.Id
j.RootUid = nj.RootUid
j.Alias = nj.Alias
j.Description = nj.Description
j.Enabled = nj.Enabled
j.CreatedAt = nj.CreatedAt
j.UpdatedAt = nj.UpdatedAt
return nil
}
func (j *Data) validate() error {
if j.Id == "" {
return errors.MissingRequiredFieldError{Name: "Id"}
}
if j.RootUid == 0 {
return errors.MissingRequiredFieldError{Name: "RootUid"}
}
if j.Alias == "" {
return errors.MissingRequiredFieldError{Name: "Alias"}
}
if j.Description == "" {
return errors.MissingRequiredFieldError{Name: "Description"}
}
if j.CreatedAt == "" {
return errors.MissingRequiredFieldError{Name: "CreatedAt"}
}
if j.UpdatedAt == "" {
return errors.MissingRequiredFieldError{Name: "UpdatedAt"}
}
return nil
}

// 返回的用户分组响应
type ModifyGroupResp = Response
type jsonResponse struct {
Data ModifyGroupData `json:"data"` // 用户分组信息
}

func (j *Response) MarshalJSON() ([]byte, error) {
if err := j.validate(); err != nil {
return nil, err
}
return json.Marshal(&jsonResponse{Data: j.Data})
}
func (j *Response) UnmarshalJSON(data []byte) error {
var nj jsonResponse
if err := json.Unmarshal(data, &nj); err != nil {
return err
}
j.Data = nj.Data
return nil
}
func (j *Response) validate() error {
if err := j.Data.validate(); err != nil {
return err
}
return nil
}

0 comments on commit d952090

Please sign in to comment.