1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 21:46:22 +01:00
Files
openshift-docs/modules/serverless-go-template.adoc
2021-05-18 14:47:05 +00:00

33 lines
1.2 KiB
Plaintext

// Module included in the following assemblies
//
// * /serverless/functions/serverless-developing-go-functions.adoc
[id="serverless-go-template_{context}"]
= Golang function template structure
When you create a Golang function using the `kn` CLI, the project directory looks like a typical Go project, with the exception of an additional `func.yaml` configuration file.
Golang 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 Golang 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
----