gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/event/v1/model.go (about) 1 // Package event code generated by oapi sdk gen 2 /* 3 * MIT License 4 * 5 * Copyright (c) 2022 Lark Technologies Pte. Ltd. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 */ 13 14 package larkevent 15 16 import ( 17 "fmt" 18 19 "context" 20 "errors" 21 22 "gitee.com/larksuite/oapi-sdk-go/v3/core" 23 ) 24 25 type ListOutboundIpReqBuilder struct { 26 apiReq *larkcore.ApiReq 27 limit int // 最大返回多少记录,当使用迭代器访问时才有效 28 } 29 30 func NewListOutboundIpReqBuilder() *ListOutboundIpReqBuilder { 31 builder := &ListOutboundIpReqBuilder{} 32 builder.apiReq = &larkcore.ApiReq{ 33 PathParams: larkcore.PathParams{}, 34 QueryParams: larkcore.QueryParams{}, 35 } 36 return builder 37 } 38 39 // 最大返回多少记录,当使用迭代器访问时才有效 40 func (builder *ListOutboundIpReqBuilder) Limit(limit int) *ListOutboundIpReqBuilder { 41 builder.limit = limit 42 return builder 43 } 44 45 // 分页大小,默认10,取值范围 10-50 46 // 47 // 示例值:10 48 func (builder *ListOutboundIpReqBuilder) PageSize(pageSize int) *ListOutboundIpReqBuilder { 49 builder.apiReq.QueryParams.Set("page_size", fmt.Sprint(pageSize)) 50 return builder 51 } 52 53 // 分页标记,第一次请求不填,表示从头开始遍历;分页查询结果还有更多项时会同时返回新的 page_token,下次遍历可采用该 page_token 获取查询结果 54 // 55 // 示例值:xxx 56 func (builder *ListOutboundIpReqBuilder) PageToken(pageToken string) *ListOutboundIpReqBuilder { 57 builder.apiReq.QueryParams.Set("page_token", fmt.Sprint(pageToken)) 58 return builder 59 } 60 61 func (builder *ListOutboundIpReqBuilder) Build() *ListOutboundIpReq { 62 req := &ListOutboundIpReq{} 63 req.apiReq = &larkcore.ApiReq{} 64 req.Limit = builder.limit 65 req.apiReq.QueryParams = builder.apiReq.QueryParams 66 return req 67 } 68 69 type ListOutboundIpReq struct { 70 apiReq *larkcore.ApiReq 71 Limit int // 最多返回多少记录,只有在使用迭代器访问时,才有效 72 73 } 74 75 type ListOutboundIpRespData struct { 76 IpList []string `json:"ip_list,omitempty"` // outbound ip 77 PageToken *string `json:"page_token,omitempty"` // 分页下次调用的page_token值 78 HasMore *bool `json:"has_more,omitempty"` // 是否还有分页数据 79 } 80 81 type ListOutboundIpResp struct { 82 *larkcore.ApiResp `json:"-"` 83 larkcore.CodeError 84 Data *ListOutboundIpRespData `json:"data"` // 业务数据 85 } 86 87 func (resp *ListOutboundIpResp) Success() bool { 88 return resp.Code == 0 89 } 90 91 type ListOutboundIpIterator struct { 92 nextPageToken *string 93 items []string 94 index int 95 limit int 96 ctx context.Context 97 req *ListOutboundIpReq 98 listFunc func(ctx context.Context, req *ListOutboundIpReq, options ...larkcore.RequestOptionFunc) (*ListOutboundIpResp, error) 99 options []larkcore.RequestOptionFunc 100 curlNum int 101 } 102 103 func (iterator *ListOutboundIpIterator) Next() (bool, string, error) { 104 // 达到最大量,则返回 105 if iterator.limit > 0 && iterator.curlNum >= iterator.limit { 106 return false, "", nil 107 } 108 109 // 为0则拉取数据 110 if iterator.index == 0 || iterator.index >= len(iterator.items) { 111 if iterator.index != 0 && iterator.nextPageToken == nil { 112 return false, "", nil 113 } 114 if iterator.nextPageToken != nil { 115 iterator.req.apiReq.QueryParams.Set("page_token", *iterator.nextPageToken) 116 } 117 resp, err := iterator.listFunc(iterator.ctx, iterator.req, iterator.options...) 118 if err != nil { 119 return false, "", err 120 } 121 122 if resp.Code != 0 { 123 return false, "", errors.New(fmt.Sprintf("Code:%d,Msg:%s", resp.Code, resp.Msg)) 124 } 125 126 if len(resp.Data.IpList) == 0 { 127 return false, "", nil 128 } 129 130 iterator.nextPageToken = resp.Data.PageToken 131 iterator.items = resp.Data.IpList 132 iterator.index = 0 133 } 134 135 block := iterator.items[iterator.index] 136 iterator.index++ 137 iterator.curlNum++ 138 return true, block, nil 139 } 140 141 func (iterator *ListOutboundIpIterator) NextPageToken() *string { 142 return iterator.nextPageToken 143 }