func/templates/go/cloudevents
Matej Vašek e720bbcc8c
Add guideline for private Go module usage (#2771)
Signed-off-by: Matej Vašek <mvasek@redhat.com>
2025-04-04 05:13:05 +00:00
..
README.md Add guideline for private Go module usage (#2771) 2025-04-04 05:13:05 +00:00
go.mod Update deps (#2531) 2024-10-07 04:34:26 +00:00
go.sum Update deps (#2531) 2024-10-07 04:34:26 +00:00
handle.go feat: improved invoke verbosity (#1007) 2022-05-11 19:16:35 +00:00
handle_test.go feat: improved invoke verbosity (#1007) 2022-05-11 19:16:35 +00:00
manifest.yaml feat: Change Invocation.format to Invoke (#1415) 2022-11-11 11:20:19 +00:00

README.md

Go Cloud Events Function

Welcome to your new Go Function! The boilerplate function code can be found in handle.go. This Function is meant to respond exclusively to Cloud Events, but you can remove the check for this in the function and it will respond just fine to plain vanilla incoming HTTP requests.

Development

Develop new features by adding a test to handle_test.go for each feature, and confirm it works with go test.

Update the running analog of the function using the func CLI or client library, and it can be invoked using a manually-created CloudEvent:

curl -v -X POST -d '{"message": "hello"}' \
  -H'Content-type: application/json' \
  -H'Ce-id: 1' \
  -H'Ce-source: cloud-event-example' \
  -H'Ce-subject: Echo content' \
  -H'Ce-type: MyEvent' \
  -H'Ce-specversion: 1.0' \
  http://localhost:8080/

Import Private Go Modules

If you want to use a module that is in a private git repository, you can do it by mounting credentials and by setting appropriate environment variable.

This is done by setting the build.volumes and build.buildEnvs properties in the func.yaml config file.

pack

For the pack builder have to use paketo bindings:

# $schema: https://raw.githubusercontent.com/knative/func/refs/heads/main/schema/func_yaml-schema.json
specVersion: 0.36.0
name: go-fn
runtime: go
created: 2025-03-17T02:02:34.196208671+01:00
build:
  buildEnvs:
    - name: SERVICE_BINDING_ROOT
      value: /bindings
  volumes:
    - hostPath: /tmp/git-binding
      path: /bindings/git-binding

s2i

For the s2i builder you have to mount credentials in .netrc format.

# $schema: https://raw.githubusercontent.com/knative/func/refs/heads/main/schema/func_yaml-schema.json
specVersion: 0.36.0
name: go-fn
runtime: go
created: 2025-03-17T02:02:34.196208671+01:00
build:
  volumes:
    - hostPath: /home/jdoe/.netrc
      path: /opt/app-root/src/.netrc

For more, see the complete documentation