func/templates
github-actions[bot] 8a9583e30f
chore: update CA bundle (#2833)
Co-authored-by: Knative Automation <automation@knative.team>
2025-05-20 15:47:28 +00:00
..
certs chore: update CA bundle (#2833) 2025-05-20 15:47:28 +00:00
go Add guideline for private Go module usage (#2771) 2025-04-04 05:13:05 +00:00
node updates node templates to ignore node_modules in .gitignore (#2713) 2025-02-26 12:48:28 +00:00
python Python Middleware v2 Scaffolding (#2685) 2025-04-02 10:44:05 +00:00
quarkus chore: update Quarkus platform version to 3.22.3 (#2832) 2025-05-16 14:38:49 +00:00
rust Remove superfluous equals sign from envvar (#2446) 2024-07-26 16:02:19 +00:00
springboot chore: update Springboot platform version to 3.4.5 (#2813) 2025-04-28 05:26:28 +00:00
typescript updates node templates to ignore node_modules in .gitignore (#2713) 2025-02-26 12:48:28 +00:00
README.md feat: scaffolded functions certs (#1823) 2023-06-26 18:57:51 +00:00
manifest.yaml feat(templates): remove liveness and readiness from defaults (#1555) 2023-02-16 08:23:51 +00:00

README.md

Templates

Contains all example source code, scaffolding, certificates and metadata used by func when creating and building function instances.

To rebuild run make templates (which caches). To force a full rebuild run make clean && make

Layout

Each directory within templates corresponds to a known language runtime. The certs directory is a reserved word containing root SSL certificates. Each directory within a runtime directory corresponds to a named templaate. The scaffolding directory within the runtime directory is a reserved word containing the adapter code that converts a function with a given method signature into a service by way of the external function runtime libraries.

Packaging

When updates are made to these templates, they must be packaged (serialized as a Go byte array) by running make templates (which rebuilds generate/zz_filesystem_generated.go, and checking in the resultant ./generate/zz_filesystem_generated.go file.

How it works

The ./generate/templates directory contains Go program that generates ./generate/zz_filesystem_generated.go. The file defines byte array variable named TemplatesZip. The variable contains ZIP representation of the templates directory. The byte array variable is then used to instantiate exported global variable function.EmbeddedTemplatesFS, which implements standard Go interfaces fs.ReadDirFS and fs.StatFS.

Rationale

Until such time as embedding static assets in binaries is included in the base go build functionality (see https://github.com/golang/go/issues/35950) we need to use our custom serialization script (./generate/templates/main.go).

Native Go embedding introduced in Go 1.16 could be used for executable binary, however it cannot be used for library. For a library we need to generate a Go source code containing the templates.