mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(README): add apigateway endpoint example (#20129)
This commit is contained in:
@@ -58,3 +58,45 @@ func main() {
|
||||
fmt.Printf("%s", jsonutils.Marshal(result).PrettyString())
|
||||
}
|
||||
```
|
||||
|
||||
使用统一API入口调用
|
||||
文档说明: https://www.cloudpods.org/docs/development/apisdk/apigateway/
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := mcclient.NewClient("https://10.127.100.2/api/s/identity/v3", // 注意此地址不带端口
|
||||
60,
|
||||
true,
|
||||
true,
|
||||
"",
|
||||
"")
|
||||
token, err := client.Authenticate("sysadmin", "7AQMP9H2umQvbxxx", "Default", "system", "Default")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s := client.NewSession(context.Background(),
|
||||
"region0",
|
||||
"",
|
||||
"apigateway", // 注意此endpoint类型
|
||||
token,
|
||||
)
|
||||
|
||||
result, err := modules.Servers.List(s, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s", jsonutils.Marshal(result).PrettyString())
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user