Skip to content

Commit

Permalink
企业微信-移除可省略的错误判断 (#734)
Browse files Browse the repository at this point in the history
Co-authored-by: markwang <www.wang61@qq.com>
  • Loading branch information
markwang1992 and markwang1992 authored Oct 10, 2023
1 parent da5067b commit 3f1c5e7
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 382 deletions.
22 changes: 7 additions & 15 deletions work/addresslist/department.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ func (r *Client) DepartmentCreate(req *DepartmentCreateRequest) (*DepartmentCrea
return nil, err
}
result := &DepartmentCreateResponse{}
if err = util.DecodeWithError(response, result, "DepartmentCreate"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "DepartmentCreate")
return result, err
}

// DepartmentSimpleList 获取子部门ID列表
Expand All @@ -101,10 +99,8 @@ func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error)
return nil, err
}
result := &DepartmentSimpleListResponse{}
if err = util.DecodeWithError(response, result, "DepartmentSimpleList"); err != nil {
return nil, err
}
return result.DepartmentID, nil
err = util.DecodeWithError(response, result, "DepartmentSimpleList")
return result.DepartmentID, err
}

// DepartmentList 获取部门列表
Expand All @@ -122,9 +118,7 @@ func (r *Client) DepartmentList() ([]*Department, error) {
}
// 按照结构体解析返回值
result := &DepartmentListResponse{}
if err = util.DecodeWithError(response, result, "DepartmentList"); err != nil {
return nil, err
}
err = util.DecodeWithError(response, result, "DepartmentList")
// 返回数据
return result.Department, err
}
Expand All @@ -144,8 +138,6 @@ func (r *Client) DepartmentGet(departmentID int) (*Department, error) {
return nil, err
}
result := &DepartmentGetResponse{}
if err = util.DecodeWithError(response, result, "DepartmentGet"); err != nil {
return nil, err
}
return &result.Department, nil
err = util.DecodeWithError(response, result, "DepartmentGet")
return &result.Department, err
}
30 changes: 10 additions & 20 deletions work/addresslist/linkedcorp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ func (r *Client) GetPermList() (*GetPermListResponse, error) {
return nil, err
}
result := &GetPermListResponse{}
if err = util.DecodeWithError(response, result, "GetPermList"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "GetPermList")
return result, err
}

// GetLinkedCorpUserRequest 获取互联企业成员详细信息请求
Expand Down Expand Up @@ -111,10 +109,8 @@ func (r *Client) GetLinkedCorpUser(req *GetLinkedCorpUserRequest) (*GetLinkedCor
return nil, err
}
result := &GetLinkedCorpUserResponse{}
if err = util.DecodeWithError(response, result, "GetLinkedCorpUser"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "GetLinkedCorpUser")
return result, err
}

// LinkedCorpSimpleListRequest 获取互联企业部门成员请求
Expand Down Expand Up @@ -151,10 +147,8 @@ func (r *Client) LinkedCorpSimpleList(req *LinkedCorpSimpleListRequest) (*Linked
return nil, err
}
result := &LinkedCorpSimpleListResponse{}
if err = util.DecodeWithError(response, result, "LinkedCorpSimpleList"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "LinkedCorpSimpleList")
return result, err
}

// LinkedCorpUserListRequest 获取互联企业部门成员详情请求
Expand Down Expand Up @@ -183,10 +177,8 @@ func (r *Client) LinkedCorpUserList(req *LinkedCorpUserListRequest) (*LinkedCorp
return nil, err
}
result := &LinkedCorpUserListResponse{}
if err = util.DecodeWithError(response, result, "LinkedCorpUserList"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "LinkedCorpUserList")
return result, err
}

// LinkedCorpDepartmentListRequest 获取互联企业部门列表请求
Expand Down Expand Up @@ -223,8 +215,6 @@ func (r *Client) LinkedCorpDepartmentList(req *LinkedCorpDepartmentListRequest)
return nil, err
}
result := &LinkedCorpDepartmentListResponse{}
if err = util.DecodeWithError(response, result, "LinkedCorpDepartmentList"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "LinkedCorpDepartmentList")
return result, err
}
30 changes: 10 additions & 20 deletions work/addresslist/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ func (r *Client) CreateTag(req *CreateTagRequest) (*CreateTagResponse, error) {
return nil, err
}
result := &CreateTagResponse{}
if err = util.DecodeWithError(response, result, "CreateTag"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "CreateTag")
return result, err
}

type (
Expand Down Expand Up @@ -129,10 +127,8 @@ func (r *Client) GetTag(tagID int) (*GetTagResponse, error) {
return nil, err
}
result := &GetTagResponse{}
if err = util.DecodeWithError(response, result, "GetTag"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "GetTag")
return result, err
}

type (
Expand Down Expand Up @@ -165,10 +161,8 @@ func (r *Client) AddTagUsers(req *AddTagUsersRequest) (*AddTagUsersResponse, err
return nil, err
}
result := &AddTagUsersResponse{}
if err = util.DecodeWithError(response, result, "AddTagUsers"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "AddTagUsers")
return result, err
}

type (
Expand Down Expand Up @@ -201,10 +195,8 @@ func (r *Client) DelTagUsers(req *DelTagUsersRequest) (*DelTagUsersResponse, err
return nil, err
}
result := &DelTagUsersResponse{}
if err = util.DecodeWithError(response, result, "DelTagUsers"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "DelTagUsers")
return result, err
}

type (
Expand Down Expand Up @@ -235,8 +227,6 @@ func (r *Client) ListTag() (*ListTagResponse, error) {
return nil, err
}
result := &ListTagResponse{}
if err = util.DecodeWithError(response, result, "ListTag"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "ListTag")
return result, err
}
40 changes: 12 additions & 28 deletions work/addresslist/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ func (r *Client) UserSimpleList(departmentID int) ([]*UserList, error) {
}
result := &UserSimpleListResponse{}
err = util.DecodeWithError(response, result, "UserSimpleList")
if err != nil {
return nil, err
}
return result.UserList, nil
return result.UserList, err
}

type (
Expand Down Expand Up @@ -153,10 +150,8 @@ func (r *Client) UserCreate(req *UserCreateRequest) (*UserCreateResponse, error)
return nil, err
}
result := &UserCreateResponse{}
if err = util.DecodeWithError(response, result, "UserCreate"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "UserCreate")
return result, err
}

// UserGetResponse 获取部门成员响应
Expand Down Expand Up @@ -245,10 +240,7 @@ func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
}
result := &UserGetResponse{}
err = util.DecodeWithError(response, result, "UserGet")
if err != nil {
return nil, err
}
return result, nil
return result, err
}

type (
Expand Down Expand Up @@ -279,10 +271,8 @@ func (r *Client) UserDelete(userID string) (*UserDeleteResponse, error) {
return nil, err
}
result := &UserDeleteResponse{}
if err = util.DecodeWithError(response, result, "UserDelete"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "UserDelete")
return result, err
}

// UserListIDRequest 获取成员ID列表请求
Expand Down Expand Up @@ -324,10 +314,8 @@ func (r *Client) UserListID(req *UserListIDRequest) (*UserListIDResponse, error)
return nil, err
}
result := &UserListIDResponse{}
if err = util.DecodeWithError(response, result, "UserListID"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "UserListID")
return result, err
}

type (
Expand Down Expand Up @@ -366,10 +354,8 @@ func (r *Client) ConvertToOpenID(userID string) (string, error) {
return "", err
}
result := &convertToOpenIDResponse{}
if err = util.DecodeWithError(response, result, "ConvertToOpenID"); err != nil {
return "", err
}
return result.OpenID, nil
err = util.DecodeWithError(response, result, "ConvertToOpenID")
return result.OpenID, err
}

type (
Expand Down Expand Up @@ -408,8 +394,6 @@ func (r *Client) ConvertToUserID(openID string) (string, error) {
return "", err
}
result := &convertToUserIDResponse{}
if err = util.DecodeWithError(response, result, "ConvertToUserID"); err != nil {
return "", err
}
return result.UserID, nil
err = util.DecodeWithError(response, result, "ConvertToUserID")
return result.UserID, err
}
6 changes: 2 additions & 4 deletions work/appchat/appchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ func (r *Client) Send(apiName string, request interface{}) (*SendResponse, error
}
// 按照结构体解析返回值
result := &SendResponse{}
if err = util.DecodeWithError(response, result, apiName); err != nil {
return nil, err
}
err = util.DecodeWithError(response, result, apiName)
// 返回数据
return result, nil
return result, err
}

// SendText 发送文本消息
Expand Down
6 changes: 2 additions & 4 deletions work/checkin/checkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResp
return nil, err
}
result := &GetCheckinDataResponse{}
if err = util.DecodeWithError(response, result, "GetCheckinData"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "GetCheckinData")
return result, err
}
4 changes: 1 addition & 3 deletions work/externalcontact/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func (r *Client) GetCallbackMessage(encryptedMsg []byte) (msg EventCallbackMessa
if err != nil {
return
}
if err = xml.Unmarshal(bData, &msg); err != nil {
return
}
err = xml.Unmarshal(bData, &msg)
return
}
30 changes: 10 additions & 20 deletions work/externalcontact/contact_way.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ func (r *Client) AddContactWay(req *AddContactWayRequest) (*AddContactWayRespons
return nil, err
}
result := &AddContactWayResponse{}
if err = util.DecodeWithError(response, result, "AddContactWay"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "AddContactWay")
return result, err
}

type (
Expand Down Expand Up @@ -153,10 +151,8 @@ func (r *Client) GetContactWay(req *GetContactWayRequest) (*GetContactWayRespons
return nil, err
}
result := &GetContactWayResponse{}
if err = util.DecodeWithError(response, result, "GetContactWay"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "GetContactWay")
return result, err
}

type (
Expand Down Expand Up @@ -195,10 +191,8 @@ func (r *Client) UpdateContactWay(req *UpdateContactWayRequest) (*UpdateContactW
return nil, err
}
result := &UpdateContactWayResponse{}
if err = util.DecodeWithError(response, result, "UpdateContactWay"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "UpdateContactWay")
return result, err
}

type (
Expand Down Expand Up @@ -236,10 +230,8 @@ func (r *Client) ListContactWay(req *ListContactWayRequest) (*ListContactWayResp
return nil, err
}
result := &ListContactWayResponse{}
if err = util.DecodeWithError(response, result, "ListContactWay"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "ListContactWay")
return result, err
}

type (
Expand Down Expand Up @@ -268,8 +260,6 @@ func (r *Client) DelContactWay(req *DelContactWayRequest) (*DelContactWayRespons
return nil, err
}
result := &DelContactWayResponse{}
if err = util.DecodeWithError(response, result, "DelContactWay"); err != nil {
return nil, err
}
return result, nil
err = util.DecodeWithError(response, result, "DelContactWay")
return result, err
}
Loading

0 comments on commit 3f1c5e7

Please sign in to comment.