This topic describes how to use SDK for Go to delete one or more event targets of an event rule.

Sample code:

package main

import (
    eventbridge "github.com/alibabacloud-go/eventbridge-sdk/eventbridge"
    console "github.com/alibabacloud-go/tea-console/client"
    util "github.com/alibabacloud-go/tea-utils/service"
    "github.com/alibabacloud-go/tea/tea"
)

/**
* Uses the CreateClient() function to initialize common request parameters.
 */
func CreateClient() (_result *eventbridge.Client, _err error) {
    config := &eventbridge.Config{}
    // Your AccessKey ID.
    config.AccessKeyId = tea.String("<accessKeyId>")
    // You AccessKey secret.
    config.AccessKeySecret = tea.String("<accessKeySecret>")
    // Your endpoint.
    config.Endpoint = tea.String("<endpoint>")
    _result = &eventbridge.Client{}
    _result, _err = eventbridge.NewClient(config)
    return _result, _err
}

func DeleteTargetsSample(client *eventbridge.Client) (_err error) {
    tryErr := func() (_e error) {
        defer func() {
            if r := tea.Recover(recover()); r ! = nil {
                _e = r
            }
        }()
        deleteTargetsResponse := &eventbridge.DeleteTargetsRequest{}
        deleteTargetsResponse.EventBusName = tea.String("demo-bus")
        deleteTargetsResponse.RuleName = tea.String("myRule")
        list := []*string{tea.String("1234")}
        deleteTargetsResponse.TargetIds = list
        response, _err := client.DeleteTargets(deleteTargetsResponse)
        if _err ! = nil {
            return _err
        }

        console.Log(tea.String("--------------------delete targets success--------------------"))
        console.Log(util.ToJSONString(tea.ToMap(response)))

        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 = DeleteTargetsSample(client)
    if _err ! = nil {
        panic(_err)
    }
}