JdcloudRequest.go raw

   1  // Copyright 2018-2025 JDCLOUD.COM
   2  //
   3  // Licensed under the Apache License, Version 2.0 (the "License");
   4  // you may not use this file except in compliance with the License.
   5  // You may obtain a copy of the License at
   6  //
   7  //     http://www.apache.org/licenses/LICENSE-2.0
   8  //
   9  // Unless required by applicable law or agreed to in writing, software
  10  // distributed under the License is distributed on an "AS IS" BASIS,
  11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12  // See the License for the specific language governing permissions and
  13  // limitations under the License.
  14  
  15  package core
  16  
  17  type RequestInterface interface {
  18  	GetURL() string
  19  	GetMethod() string
  20  	GetVersion() string
  21  	GetHeaders() map[string]string
  22  	GetRegionId() string
  23  }
  24  
  25  // JDCloudRequest is the base struct of service requests
  26  type JDCloudRequest struct {
  27  	URL     string // resource url, i.e. /regions/${regionId}/elasticIps/${elasticIpId}
  28  	Method  string
  29  	Header  map[string]string
  30  	Version string
  31  }
  32  
  33  func (r JDCloudRequest) GetURL() string {
  34  	return r.URL
  35  }
  36  
  37  func (r JDCloudRequest) GetMethod() string {
  38  	return r.Method
  39  }
  40  
  41  func (r JDCloudRequest) GetVersion() string {
  42  	return r.Version
  43  }
  44  
  45  func (r JDCloudRequest) GetHeaders() map[string]string {
  46  	return r.Header
  47  }
  48  
  49  // AddHeader only adds pin or erp, they will be encoded to base64 code
  50  func (r *JDCloudRequest) AddHeader(key, value string) {
  51  	if r.Header == nil {
  52  		r.Header = make(map[string]string)
  53  	}
  54  	r.Header[key] = value
  55  }
  56