This repo serves as a util package for common functionalities such as logging of the Keptn Project.
Please post any issues with this package to the keptn/keptn repository and label them with area:go-utils
.
Get the latest version using
go get github.com/keptn/go-utils
Also consider browsing our Releases Page to find out about all releases.
If you want to contribute, just create a PR on the master branch.
Please also see CONTRIBUTING.md instructions on how to contribute.
Below we have listed some basic examples. You can find more information about the usage within the docs/ folder.
If you need to access several utility functions:
import {
"github.com/keptn/go-utils/pkg/lib"
}
This module provides you with a convenient Keptn
helper struct that allows you to access several resources that are relevant within the context of a
Keptn event. The helper struct can be initialized by passing a CloudEvent to the NewKeptn
function. Example:
func HandleEvent(event cloudevents.Event) error {
keptnHandler, err := keptn.NewKeptn(&event, keptn.KeptnOpts{})
if err != nil {
return nil, err
}
// get the shipyard file of the project
shipyard, _ := keptnHandler.GetShipyard()
// get a resource within the current context (i.e., project, stage, service) of the event
resourceContent, _ := keptnHandler.GetKeptnResource("resource.yaml")
// send a cloud event
_ = keptnHandler.SendCloudEvent(event)
// ...
}
If you need to access data within CloudEvents:
import {
"github.com/keptn/go-utils/pkg/lib"
)
Example:
func parseCloudEvent(event cloudevents.Event) (keptnevents.TestFinishedEventData, error) {
eventData := &keptn.TestsFinishedEventData{}
err := event.DataAs(eventData)
return eventData, err
}
If you need to access Models for YAML files:
import {
"github.com/keptn/go-utils/pkg/lib"
)
After updating the model definitions in the swagger.yaml
file, execute the command
swagger generate model --spec=swagger.yaml -t=./pkg/api/
to update the models located in ./pkg/api/models
Within .travis.yml we have included an automation that creates a Pull Request to
github.com/keptn/keptn to update go.mod
files with an updated version of this
package (based on the commit hash). To make this work, a GITHUB_TOKEN
(personal access token)
needs to be added within the travis-ci settings page.