-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: corvofeng <corvofeng@gmail.com>
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kmtencentcloud | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" | ||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | ||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" | ||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions" | ||
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" | ||
) | ||
|
||
func xx() { | ||
// 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。 | ||
// 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。 | ||
// credential := common.NewCredential("SecretId", "SecretKey") | ||
credential := common.NewCredential( | ||
os.Getenv("TENCENTCLOUD_SECRET_ID"), | ||
os.Getenv("TENCENTCLOUD_SECRET_KEY"), | ||
) | ||
client, _ := cvm.NewClient(credential, regions.Singapore, profile.NewClientProfile()) | ||
|
||
request := cvm.NewDescribeInstancesRequest() | ||
response, err := client.DescribeInstances(request) | ||
|
||
if _, ok := err.(*errors.TencentCloudSDKError); ok { | ||
fmt.Printf("An API error has returned: %s", err) | ||
return | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("%s\n", response.ToJsonString()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kmtencentcloud | ||
|
||
import "testing" | ||
|
||
func TestXX(t *testing.T) { | ||
xx() | ||
} |