18 · Modules
Go with extern
Go functions, module dependencies and callbacks from Zolo.
On this page
Import go from the plugin of the same name. Function signatures use Zolo
types; bodies use Go and may start with native imports. Run these examples with
the CLI and an installed Go plugin.
Call typed Go functions, import an exported function and await a worker operation.
// parity-timeout-ms:300000
use plugin go::{go}
extern go fn exact(value: int) -> int {
return value
}
extern go fn upper(value: str) -> str {
import "strings"
return strings.ToUpper(value)
}
extern go async fn later(value: int) -> int {
return value + 1
}
extern go from "./go_fixtures/math.go" use {Add}
print(exact(9007199254740993)) // expected: 9007199254740993
print(upper("hello Go")) // expected: HELLO GO
print(Add(left: 20, right: 22)) // expected: 42
print(await later(41)) // expected: 42
Requires the Zolo CLI/host — open in the playground or run locally.
int maps to int64, float to float64, str to string,
bytes to []byte and arrays to slices. Public structs and string-keyed maps
become copied records. Native narrow and unsigned integer conversions are
checked. Receiver methods, generic and variadic exports need a concrete exported
free-function adapter.
A source import follows the importing Zolo file:
extern go from "./math.go" use {Add}.
Exported parameter names support ordinary named calls, such as
Add(left: 20, right: 22).
Modules
Pin a module version once and use its native import in a Go function.
// Prepare with zolo install or opt into zolo run ... --install=auto.
use plugin go::{go}
extern go deps {
"github.com/google/uuid" = "v1.6.0"
}
extern go fn valid(value: str) -> bool {
import "github.com/google/uuid"
_, err := uuid.Parse(value)
return err == nil
}
print(valid("c9bba9c7-9d7a-4fbb-a2a5-dd344c9be6d1")) // expected: true
Requires the Zolo CLI/host — open in the playground or run locally.
For a larger project, move the package declaration to the manifest:
[foreign.go.dependencies]
"github.com/google/uuid" = "v1.6.0"
Run zolo install main.zolo, then
zolo run main.zolo --offline --frozen. Resolution records the selected
transitive graph, module hashes and a private module cache. Compilation uses
that closed environment with GOPROXY=off, GOWORK=off,
GOTOOLCHAIN=local and read-only module selection. An exact direct version
that Go's module selection would upgrade reports a conflict. Native cgo package
assets still require an explicit deployment closure.
Callbacks, async and deployment
A parameter fn(int) -> int becomes a Go func adapter valid during the
invocation. It supports calls back into Zolo and nested foreign calls. Do not
retain the borrowed callback or invoke it from an independent goroutine.
extern go async fn runs ordinary Go code on an invocation worker and exposes
its completion as a Zolo Future. A goroutine by itself does not define that
completion. Cancellation closes callback and result delivery; it cannot stop
arbitrary native work. (T, error) failures and panics from the exported call
become structured Zolo errors. Unrelated goroutine panics and unrecoverable native
faults retain their normal process semantics.
Preparation needs Go, cgo and a compatible C compiler. ZOLO_GO selects Go
and CC selects its cgo compiler. Native editor queries use gopls through
ZOLO_GOPLS. Analysis preserves unsaved text and never loads the authored
library or runs its init functions.
Compiled artifacts contain machine code, metadata and source snapshots. VM, native and LLVM support dynamic, embedded and static plugin packaging without original sources, Go, a compiler or a module cache at deployment. Artifacts match their OS/architecture. Hosted wasm-aot execution is unavailable; runtime acceptance currently covers Windows x64.
See also