Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
To build the Go application, we will use the template I prepared in https://github.com/MartinHeinz/go-github-app. This application is ready to be used as GitHub app and all that's missing in it, are a couple of variables which we saved during setup in previous section. The repository contains convenience script which you can use to populate all the values:
If the event name matches one of the options we proceed with loading the JSON payload into a EventPayload struct, which is defined in cmd/app/webhook/models.go. It's just a struct generated using https://mholt.github.io/json-to-go/ with unnecessary fields stripped.
Next we need to go to https://github.com/settings/apps/new to configure the integration. Fill the fields as follows:
So far we've been testing the app with localtunnel, which is nice for quick ad-hoc tests against live API, but it doesn't replace proper unit tests. To write unit tests for this app, we need to mock-out the API to avoid being dependent on the external service. To do so, we can use go-github-mock:
Related posts
- JSON to Go Struct Converter
- Need a pointer on how I can unmarshal this json
- Ask HN: What are some Golang tools you can't live without?
- how to efficiently create structs to match the json response
- Is there a library or tool I can use to avoid manually setting json keys i.e. ‘json:”name”’ next to fields in structs?