This topic describes how to use SDK for Go to update the settings 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"
    "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>")
    // Your 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 UpdateEventRuleSample(client *eventbridge.Client) (_err error) {
    tryErr := func() (_e error) {
        defer func() {
            if r := tea.Recover(recover()); r ! = nil {
                _e = r
            }
        }()
        updateEventRuleRequest := &eventbridge.UpdateRuleRequest{}
        updateEventRuleRequest.EventBusName = tea.String("demo-bus")
        updateEventRuleRequest.RuleName = tea.String("myRule")
        updateEventRuleRequest.FilterPattern = tea.String("{\"source\":[\"acs.oss\"],\"type\":[\"oss:BucketQueried:GetBucketStat\"]}")
        _, _err = client.UpdateRule(updateEventRuleRequest)
        if _err ! = nil {
            return _err
        }
        console.Log(tea.String("--------------------update rule 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 = UpdateEventRuleSample(client)
    if _err ! = nil {
        panic(_err)
    }
}