本文介绍如何使用Go SDK查询所有事件总线。

示例代码如下:

package main
import (
"fmt"
eventbridge "github.com/alibabacloud-go/eventbridge-sdk/eventbridge"
console "github.com/alibabacloud-go/tea-console/client"
"github.com/alibabacloud-go/tea/tea"
)

/**
* Create client初始化公共请求参数。
 */
func CreateClient() (_result *eventbridge.Client, _err error) {
	config := &eventbridge.Config{}
	// 您的AccessKey ID。
	config.AccessKeyId = tea.String("<accessKeyId>")
	// 您的AccessKey Secret。
	config.AccessKeySecret = tea.String("<accessKeySecret>")
	// 您的接入点。
	config.Endpoint = tea.String("<endpoint>")
	_result = &eventbridge.Client{}
	_result, _err = eventbridge.NewClient(config)
	return _result, _err
}

func ListEventBusesSample(client *eventbridge.Client) (_err error) {
	tryErr := func() (_e error) {
		defer func() {
			if r := tea.Recover(recover()); r != nil {
				_e = r
			}
		}()
		listEventBusesRequest := &eventbridge.ListEventBusesRequest{}
		resp, _err := client.ListEventBuses(listEventBusesRequest)
		if _err != nil {
			return _err
		}
		fmt.Println(resp)
		console.Log(tea.String("--------------------list buses success--------------------"))

		return nil
	}()

	_err = tryErr
	if tryErr != nil {
		var error = &tea.SDKError{}
		if _t, ok := tryErr.(*tea.SDKError); ok {
			error = _t
		} else {
			error.SetErrMsg(tryErr.Error())
		}
		console.Log(error.Message)
	}
	return _err
}

func main() {
	client, _err := CreateClient()
	if _err != nil {
		panic(_err)
	}

	_err = ListEventBusesSample(client)
	if _err != nil {
		panic(_err)
	}
}