mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
34 lines
1.2 KiB
Plaintext
34 lines
1.2 KiB
Plaintext
// Module included in the following assemblies
|
|
//
|
|
// * serverless/functions/serverless-developing-go-functions.adoc
|
|
|
|
:_mod-docs-content-type: REFERENCE
|
|
[id="serverless-go-template_{context}"]
|
|
= Go function template structure
|
|
|
|
When you create a Go function using the Knative (`kn`) CLI, the project directory looks like a typical Go project. The only exception is the additional `func.yaml` configuration file, which is used for specifying the image.
|
|
|
|
Go functions have few restrictions. The only requirements are that your project must be defined in a `function` module, and must export the function `Handle()`.
|
|
|
|
Both `http` and `event` trigger functions have the same template structure:
|
|
|
|
.Template structure
|
|
[source,terminal]
|
|
----
|
|
fn
|
|
├── README.md
|
|
├── func.yaml <1>
|
|
├── go.mod <2>
|
|
├── go.sum
|
|
├── handle.go
|
|
└── handle_test.go
|
|
----
|
|
<1> The `func.yaml` configuration file is used to determine the image name and registry.
|
|
<2> You can add any required dependencies to the `go.mod` file, which can include additional local Go files. When the project is built for deployment, these dependencies are included in the resulting runtime container image.
|
|
+
|
|
.Example of adding dependencies
|
|
[source,terminal]
|
|
----
|
|
$ go get gopkg.in/yaml.v2@v2.4.0
|
|
----
|