gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/core/reqoption.go (about)

     1  /*
     2   * MIT License
     3   *
     4   * Copyright (c) 2022 Lark Technologies Pte. Ltd.
     5   *
     6   * 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:
     7   *
     8   * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
     9   *
    10   * 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.
    11   */
    12  
    13  package larkcore
    14  
    15  import "net/http"
    16  
    17  type RequestOption struct {
    18  	TenantKey         string
    19  	UserAccessToken   string
    20  	AppAccessToken    string
    21  	TenantAccessToken string
    22  	NeedHelpDeskAuth  bool
    23  	RequestId         string
    24  	AppTicket         string
    25  	FileUpload        bool
    26  	FileDownload      bool
    27  	Header            http.Header
    28  }
    29  
    30  type RequestOptionFunc func(option *RequestOption)
    31  
    32  func WithNeedHelpDeskAuth() RequestOptionFunc {
    33  	return func(option *RequestOption) {
    34  		option.NeedHelpDeskAuth = true
    35  	}
    36  }
    37  
    38  func WithRequestId(requestId string) RequestOptionFunc {
    39  	return func(option *RequestOption) {
    40  		option.RequestId = requestId
    41  	}
    42  }
    43  
    44  func WithTenantKey(tenantKey string) RequestOptionFunc {
    45  	return func(option *RequestOption) {
    46  		option.TenantKey = tenantKey
    47  	}
    48  }
    49  
    50  func WithAppTicket(appTicket string) RequestOptionFunc {
    51  	return func(option *RequestOption) {
    52  		option.AppTicket = appTicket
    53  	}
    54  }
    55  
    56  func WithFileUpload() RequestOptionFunc {
    57  	return func(option *RequestOption) {
    58  		option.FileUpload = true
    59  	}
    60  }
    61  
    62  func WithFileDownload() RequestOptionFunc {
    63  	return func(option *RequestOption) {
    64  		option.FileDownload = true
    65  	}
    66  }
    67  
    68  func WithHeaders(header http.Header) RequestOptionFunc {
    69  	return func(option *RequestOption) {
    70  		option.Header = header
    71  	}
    72  }
    73  
    74  func WithUserAccessToken(userAccessToken string) RequestOptionFunc {
    75  	return func(option *RequestOption) {
    76  		option.UserAccessToken = userAccessToken
    77  	}
    78  }
    79  
    80  func WithTenantAccessToken(tenantAccessToken string) RequestOptionFunc {
    81  	return func(option *RequestOption) {
    82  		option.TenantAccessToken = tenantAccessToken
    83  	}
    84  }