client.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package amqp_open
  2. //Licensed under the Apache License, Version 2.0 (the "License");
  3. //you may not use this file except in compliance with the License.
  4. //You may obtain a copy of the License at
  5. //
  6. //http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. //Unless required by applicable law or agreed to in writing, software
  9. //distributed under the License is distributed on an "AS IS" BASIS,
  10. //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. //See the License for the specific language governing permissions and
  12. //limitations under the License.
  13. //
  14. // Code generated by Alibaba Cloud SDK Code Generator.
  15. // Changes may cause incorrect behavior and will be lost if the code is regenerated.
  16. import (
  17. "reflect"
  18. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  19. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth"
  20. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider"
  21. )
  22. // Client is the sdk client struct, each func corresponds to an OpenAPI
  23. type Client struct {
  24. sdk.Client
  25. }
  26. // SetClientProperty Set Property by Reflect
  27. func SetClientProperty(client *Client, propertyName string, propertyValue interface{}) {
  28. v := reflect.ValueOf(client).Elem()
  29. if v.FieldByName(propertyName).IsValid() && v.FieldByName(propertyName).CanSet() {
  30. v.FieldByName(propertyName).Set(reflect.ValueOf(propertyValue))
  31. }
  32. }
  33. // SetEndpointDataToClient Set EndpointMap and ENdpointType
  34. func SetEndpointDataToClient(client *Client) {
  35. SetClientProperty(client, "EndpointMap", GetEndpointMap())
  36. SetClientProperty(client, "EndpointType", GetEndpointType())
  37. }
  38. // NewClient creates a sdk client with environment variables
  39. func NewClient() (client *Client, err error) {
  40. client = &Client{}
  41. err = client.Init()
  42. SetEndpointDataToClient(client)
  43. return
  44. }
  45. // NewClientWithProvider creates a sdk client with providers
  46. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  47. func NewClientWithProvider(regionId string, providers ...provider.Provider) (client *Client, err error) {
  48. client = &Client{}
  49. var pc provider.Provider
  50. if len(providers) == 0 {
  51. pc = provider.DefaultChain
  52. } else {
  53. pc = provider.NewProviderChain(providers)
  54. }
  55. err = client.InitWithProviderChain(regionId, pc)
  56. SetEndpointDataToClient(client)
  57. return
  58. }
  59. // NewClientWithOptions creates a sdk client with regionId/sdkConfig/credential
  60. // this is the common api to create a sdk client
  61. func NewClientWithOptions(regionId string, config *sdk.Config, credential auth.Credential) (client *Client, err error) {
  62. client = &Client{}
  63. err = client.InitWithOptions(regionId, config, credential)
  64. SetEndpointDataToClient(client)
  65. return
  66. }
  67. // NewClientWithAccessKey is a shortcut to create sdk client with accesskey
  68. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  69. func NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret string) (client *Client, err error) {
  70. client = &Client{}
  71. err = client.InitWithAccessKey(regionId, accessKeyId, accessKeySecret)
  72. SetEndpointDataToClient(client)
  73. return
  74. }
  75. // NewClientWithStsToken is a shortcut to create sdk client with sts token
  76. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  77. func NewClientWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken string) (client *Client, err error) {
  78. client = &Client{}
  79. err = client.InitWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken)
  80. SetEndpointDataToClient(client)
  81. return
  82. }
  83. // NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn
  84. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  85. func NewClientWithRamRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) {
  86. client = &Client{}
  87. err = client.InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName)
  88. SetEndpointDataToClient(client)
  89. return
  90. }
  91. // NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn and policy
  92. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  93. func NewClientWithRamRoleArnAndPolicy(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (client *Client, err error) {
  94. client = &Client{}
  95. err = client.InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy)
  96. SetEndpointDataToClient(client)
  97. return
  98. }
  99. // NewClientWithEcsRamRole is a shortcut to create sdk client with ecs ram role
  100. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  101. func NewClientWithEcsRamRole(regionId string, roleName string) (client *Client, err error) {
  102. client = &Client{}
  103. err = client.InitWithEcsRamRole(regionId, roleName)
  104. SetEndpointDataToClient(client)
  105. return
  106. }
  107. // NewClientWithRsaKeyPair is a shortcut to create sdk client with rsa key pair
  108. // usage: https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md
  109. func NewClientWithRsaKeyPair(regionId string, publicKeyId, privateKey string, sessionExpiration int) (client *Client, err error) {
  110. client = &Client{}
  111. err = client.InitWithRsaKeyPair(regionId, publicKeyId, privateKey, sessionExpiration)
  112. SetEndpointDataToClient(client)
  113. return
  114. }