Creating Go Code-only Functions
Find out how to package and create Go code-only functions in OCI Functions.
Use a Go code-only function when you want to deploy a Go function without building and publishing a container image
Go code-only functions run from statically linked, self-contained Linux executable binaries.
Before creating a Go code-only function, package the Go executable using the archive layout required for the application's architecture. For general code-only function prerequisites, see Creating Code-only Functions. For the runtime name to use with Go code-only functions, see Languages supported for code-only functions.
In addition, for packaging and creating Go code-only functions, you need:
- A Go development environment.
- Go function source code.
- Ability to build statically linked, self-contained Linux executable binaries for the target application architecture.
Go archive requirements
For Go code-only functions:
- The executable must be a statically linked, self-contained Linux executable binary.
- The executable file must be named
func. - Go binaries are architecture-specific.
- A binary built for macOS or Windows cannot run directly in the OCI Functions Linux runtime.
- A binary built for x86 cannot run on ARM.
- A binary built for ARM cannot run on x86.
- Multi-architecture applications require one binary per architecture.
Go build target values
Build the Go executable for Linux and for the processor architecture used by the OCI Functions application.
| Application architecture | GOOS |
GOARCH |
|---|---|---|
| x86 | linux |
amd64 |
| Arm | linux |
arm64 |
Single-architecture Go archive
For a single-architecture application, package a statically linked, self-contained Linux executable binary named func at the archive root.
archive-root/
├── func
└── resources/ # optional
Rules:
funcis required at the archive root.resources/is optional.- The archive is invalid if
funcis missing. - The binary must be statically linked, self-contained, and built for Linux and for the target architecture of the application.
Example for x86:
GOOS=linux GOARCH=amd64 go build -o func .
zip function.zip func
Example for ARM:
GOOS=linux GOARCH=arm64 go build -o func .
zip function.zip func
If using resources:
zip -r function.zip func resources/
Multi-architecture Go archive
For a multi-architecture application, package a statically linked, self-contained Linux executable binary named func for each supported architecture in the corresponding architecture directory.
archive-root/
├── fn-arch-x86/
├── func
└── resources/ # optional
└── fn-arch-arm/
├── func
└── resources/ # optional
Rules:
fn-arch-x86/is required.fn-arch-arm/is required.- Each architecture directory must contain a binary named
func. - The archive is invalid if either architecture directory is missing.
- The archive is invalid if either architecture directory is missing
func. - Each binary must be statically linked, self-contained, and built for Linux and for the corresponding architecture.
Example:
mkdir -p fn-arch-x86 fn-arch-arm
GOOS=linux GOARCH=amd64 go build -o fn-arch-x86/func .
GOOS=linux GOARCH=arm64 go build -o fn-arch-arm/func .
zip -r function.zip fn-arch-x86 fn-arch-arm
Optional resources directory
Use the optional resources/ directory for files the function needs at runtime, such as static files, templates, or configuration files.
For single-architecture archives, place resources/ at the archive root. For multi-architecture archives, place architecture-specific resources under each architecture directory if needed.
Creating a Go code-only function
To create a Go code-only function, follow the instructions in Creating Code-only Functions. For example, to create a Go code-only function using the Console:
- On the Applications list page, select the application in which you want to create the Go code-only function. If you need help finding the list page or the application, see Listing Applications.
-
Select the Functions tab.
The Functions list page opens. All functions in the selected application are displayed in a table.
- Select Create from archive and specify details for the Go code-only function, including the file source, the Go archive, and the supported runtime for Go code-only functions.
For Go code-only functions, do not specify a separate handler value. The archive must contain a Linux executable named
funcin the required location. - Specify other details for the function as required (see Creating Code-only Functions).
- Select Create to create the function.
The Go code-only function is created and can be invoked like any other function.
Troubleshooting
| Error Code | Problem | Likely cause | Recommended fix |
|---|---|---|---|
400 |
Archive validation fails because func is missing |
The binary is not at the expected path | Put func at the archive root for single-architecture applications, or under both architecture directories for multi-architecture applications. |
400 |
Function fails after deployment | Binary was built for the wrong operating system or architecture | Rebuild with GOOS=linux and the correct GOARCH. |
400 |
Multi-architecture archive is rejected | One architecture directory is missing | Include both fn-arch-x86/ and fn-arch-arm/. |
400 |
Multi-architecture archive is rejected because one binary is missing | One architecture directory does not include func |
Build and include func under both architecture directories. |
400 |
Resources are not found at runtime | Resources were packaged in an unexpected location | Use the supported resources/ directory structure. |
500 |
Processing of archive file failed | Transient error | Retry, or contact Oracle Support. |