gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/event/v1/api.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  	"context"
    18  	"net/http"
    19  
    20  	"gitee.com/larksuite/oapi-sdk-go/v3/core"
    21  )
    22  
    23  func NewService(config *larkcore.Config) *EventService {
    24  	e := &EventService{config: config}
    25  	e.OutboundIp = &outboundIp{service: e}
    26  	return e
    27  }
    28  
    29  type EventService struct {
    30  	config     *larkcore.Config
    31  	OutboundIp *outboundIp // 事件出口IP
    32  }
    33  
    34  type outboundIp struct {
    35  	service *EventService
    36  }
    37  
    38  // 获取事件出口IP
    39  //
    40  // - 飞书开放平台向应用配置的回调地址推送事件时,是通过特定的IP发送出去的。如果企业需要做防火墙配置,那么可以通过这个接口获取到所有相关的IP段。
    41  //
    42  // - IP段有变更可能,建议企业每隔6小时定时拉取IP段更新防火墙设置,这样因IP变更导致推送失败的事件还可以通过重试解决。
    43  //
    44  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uYDNxYjL2QTM24iN0EjN/event-v1/outbound_ip/list
    45  //
    46  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/eventv1/list_outboundIp.go
    47  func (o *outboundIp) List(ctx context.Context, req *ListOutboundIpReq, options ...larkcore.RequestOptionFunc) (*ListOutboundIpResp, error) {
    48  	// 发起请求
    49  	apiReq := req.apiReq
    50  	apiReq.ApiPath = "/open-apis/event/v1/outbound_ip"
    51  	apiReq.HttpMethod = http.MethodGet
    52  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    53  	apiResp, err := larkcore.Request(ctx, apiReq, o.service.config, options...)
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  	// 反序列响应结果
    58  	resp := &ListOutboundIpResp{ApiResp: apiResp}
    59  	err = apiResp.JSONUnmarshalBody(resp)
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  	return resp, err
    64  }
    65  func (o *outboundIp) ListByIterator(ctx context.Context, req *ListOutboundIpReq, options ...larkcore.RequestOptionFunc) (*ListOutboundIpIterator, error) {
    66  	return &ListOutboundIpIterator{
    67  		ctx:      ctx,
    68  		req:      req,
    69  		listFunc: o.List,
    70  		options:  options,
    71  		limit:    req.Limit}, nil
    72  }