You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
cloudevents "github.com/cloudevents/sdk-go/v2"
keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0""github.com/warber/keptn-sdk-go/pkg/sdk""log"
)
funcmain() {
// 1. create a HTTP clienthttpClient:=sdk.GetHTTPClient(cloudevents.WithPath("/"), cloudevents.WithPort(8080))
// 2. create keptn and register our handlersmyKeptn:=sdk.NewKeptn(httpClient, "my-service", sdk.WithHandler(GreetingsHandler{}, "sh.keptn.event.greeting.triggered"))
// 3. startmyKeptn.Start()
}
// GreetingsHandler is our custom handler to handle greetings.triggered eventstypeGreetingsHandlerstruct {
}
// Execute is called whenever a "greetings.triggered" event was receivedfunc (mGreetingsHandler) Execute(ceinterface{}, context sdk.Context) (error, sdk.Context) {
greetingTriggeredData:=ce.(*GreetingTriggeredData)
// [...]// do stuff with your data// [...]// when we are done we set the finished datacontext.SetFinishedData(GreetingFinishedData{GreetMessage: greetingTriggeredData.GreetMessage})
returnnil, context
}
// GetData returns the type of data we want to processfunc (mGreetingsHandler) GetData() interface{} {
return&GreetingTriggeredData{}
}
// GreetingTriggeredData is our custom event data we want to processtypeGreetingTriggeredDatastruct {
keptnv2.EventDataGreetMessagestring`json:"greetMessage"`
}
// GreetingFInishedData is our custom event data we want to send out when our task processing is finishedtypeGreetingFinishedDatastruct {
keptnv2.EventDataGreetMessagestring`json:"greetMessage"`
}