Dagger
Search

go

Go CLI surface (build, test, vet, fmt, run, generate, install, mod*, work,
env, version) so downstream pipelines can compose Go workflows without
re-inventing toolchain pinning, cache mounts, and container plumbing.

Toolchain version is pinned via New(version) or inferred from the source's
go.mod `go` directive; falls back to "latest" when no go directive is
found. Every container mounts the shared `go-mod-cache` and
`go-build-cache` Dagger cache volumes.

Installation

dagger install github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e

Entrypoint

Return Type
Go !
Arguments
NameTypeDefault ValueDescription
versionString -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
func (m *MyModule) Example() *dagger.Go  {
	return dag.
			Go()
}
@function
def example() -> dagger.Go:
	return (
		dag.go()
	)
@func()
example(): Go {
	return dag
		.go()
}

Types

Go 🔗

Go wraps the Go CLI as Dagger functions. Construct via New(); call Container() for the prepared base container, or use the per-CLI helpers (Build, Test, Vet, …) which reuse the same backing container.

version() 🔗

Version is the pinned Go toolchain version (e.g. “1.23”). Empty means infer from the supplied source’s go.mod go directive; falls back to “latest” when no go directive is found.

Return Type
String !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 version
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Go().
			Version(ctx)
}
@function
async def example() -> str:
	return await (
		dag.go()
		.version()
	)
@func()
async example(): Promise<string> {
	return dag
		.go()
		.version()
}

build() 🔗

Build runs go build -o /out/[output] [flags] pkg against the supplied source and returns /out as a *dagger.Directory. pkg defaults to ./...; when output is empty, -o /out/ is used so go build picks names per its own rules (one binary per main package).

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
pkgString !"./..."No description provided
outputString -No description provided
flags[String ! ] -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 build --source DIR_PATH --pkg string
func (m *MyModule) Example(source *dagger.Directory, pkg string) *dagger.Directory  {
	return dag.
			Go().
			Build(source, pkg)
}
@function
def example(source: dagger.Directory, pkg: str) -> dagger.Directory:
	return (
		dag.go()
		.build(source, pkg)
	)
@func()
example(source: Directory, pkg: string): Directory {
	return dag
		.go()
		.build(source, pkg)
}

ci() 🔗

Ci returns a new pipeline builder bound to the supplied source.

Return Type
Ci !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH
func (m *MyModule) Example(source *dagger.Directory) *dagger.GoCi  {
	return dag.
			Go().
			Ci(source)
}
@function
def example(source: dagger.Directory) -> dagger.GoCi:
	return (
		dag.go()
		.ci(source)
	)
@func()
example(source: Directory): GoCi {
	return dag
		.go()
		.ci(source)
}

container() 🔗

Container returns the prepared base container with go-mod-cache mounted at /go/pkg/mod, go-build-cache mounted at /root/.cache/go-build, source mounted at /src, and the working directory set to /src. Use this as an escape hatch when a Go command isn’t covered by the typed helpers.

The toolchain image is golang: where version comes from New() or, when New(“”) was used, from source/go.mod’s go directive (fallback “latest”). The signature takes ctx + returns error because go.mod inspection requires async I/O.

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 container --source DIR_PATH
func (m *MyModule) Example(source *dagger.Directory) *dagger.Container  {
	return dag.
			Go().
			Container(source)
}
@function
def example(source: dagger.Directory) -> dagger.Container:
	return (
		dag.go()
		.container(source)
	)
@func()
example(source: Directory): Container {
	return dag
		.go()
		.container(source)
}

env() 🔗

Env runs go env in a source-less base container and returns its stdout.

Return Type
String !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 env
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Go().
			Env(ctx)
}
@function
async def example() -> str:
	return await (
		dag.go()
		.env()
	)
@func()
async example(): Promise<string> {
	return dag
		.go()
		.env()
}

fmt() 🔗

Fmt runs gofmt -l -d . against the supplied source. Returns the diff of any unformatted files; non-empty output is also returned as an error so CI fails fast on formatting violations.

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 fmt --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Go().
			Fmt(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.go()
		.fmt(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.go()
		.fmt(source)
}

generate() 🔗

Generate runs go generate pkg against the supplied source and returns /src after generation. pkg defaults to ./....

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
pkgString !"./..."No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 generate --source DIR_PATH --pkg string
func (m *MyModule) Example(source *dagger.Directory, pkg string) *dagger.Directory  {
	return dag.
			Go().
			Generate(source, pkg)
}
@function
def example(source: dagger.Directory, pkg: str) -> dagger.Directory:
	return (
		dag.go()
		.generate(source, pkg)
	)
@func()
example(source: Directory, pkg: string): Directory {
	return dag
		.go()
		.generate(source, pkg)
}

install() 🔗

Install runs go install pkg in a source-less base container with GOBIN=/out and returns the resulting binary as a *dagger.File. The returned filename is the basename of pkg (with any @version suffix stripped), matching go install’s naming rules.

pkg MUST be pinned to an explicit version (e.g. pkg@v1.2.3 or a commit-hash pseudo-version); @latest and bare paths are rejected. The pin is what makes the result safe to cache across calls within a session — without it, the proxy could resolve different versions on successive invocations.

Return Type
File !
Arguments
NameTypeDefault ValueDescription
pkgString !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 install --pkg string
func (m *MyModule) Example(pkg string) *dagger.File  {
	return dag.
			Go().
			Install(pkg)
}
@function
def example(pkg: str) -> dagger.File:
	return (
		dag.go()
		.install(pkg)
	)
@func()
example(pkg: string): File {
	return dag
		.go()
		.install(pkg)
}

modDownload() 🔗

ModDownload runs go mod download against the supplied source.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 mod-download --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory)   {
	return dag.
			Go().
			Moddownload(ctx, source)
}
@function
async def example(source: dagger.Directory) -> None:
	return await (
		dag.go()
		.moddownload(source)
	)
@func()
async example(source: Directory): Promise<void> {
	return dag
		.go()
		.modDownload(source)
}

modTidy() 🔗

ModTidy runs go mod tidy against the supplied source and returns the updated /src directory.

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 mod-tidy --source DIR_PATH
func (m *MyModule) Example(source *dagger.Directory) *dagger.Directory  {
	return dag.
			Go().
			Modtidy(source)
}
@function
def example(source: dagger.Directory) -> dagger.Directory:
	return (
		dag.go()
		.modtidy(source)
	)
@func()
example(source: Directory): Directory {
	return dag
		.go()
		.modTidy(source)
}

modVerify() 🔗

ModVerify runs go mod verify against the supplied source.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 mod-verify --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory)   {
	return dag.
			Go().
			Modverify(ctx, source)
}
@function
async def example(source: dagger.Directory) -> None:
	return await (
		dag.go()
		.modverify(source)
	)
@func()
async example(source: Directory): Promise<void> {
	return dag
		.go()
		.modVerify(source)
}

run() 🔗

Run runs go run pkg [args...] against the supplied source and returns the program’s stdout. pkg is required (a single runnable main package).

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
pkgString !-No description provided
args[String ! ] -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 run --source DIR_PATH --pkg string
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory, pkg string) string  {
	return dag.
			Go().
			Run(ctx, source, pkg)
}
@function
async def example(source: dagger.Directory, pkg: str) -> str:
	return await (
		dag.go()
		.run(source, pkg)
	)
@func()
async example(source: Directory, pkg: string): Promise<string> {
	return dag
		.go()
		.run(source, pkg)
}

test() 🔗

Test runs go test -count=1 [-race] [flags] pkg against the supplied source and returns the combined stdout. -count=1 is always passed to bypass Go’s internal test cache.

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
pkgString !"./..."No description provided
raceBoolean !falseNo description provided
flags[String ! ] -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 test --source DIR_PATH --pkg string --race boolean
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory, pkg string, race bool) string  {
	return dag.
			Go().
			Test(ctx, source, pkg, race)
}
@function
async def example(source: dagger.Directory, pkg: str, race: bool) -> str:
	return await (
		dag.go()
		.test(source, pkg, race)
	)
@func()
async example(source: Directory, pkg: string, race: boolean): Promise<string> {
	return dag
		.go()
		.test(source, pkg, race)
}

toolVersion() 🔗

ToolVersion runs go version in a source-less base container and returns the trimmed output (e.g. “go version go1.23.0 linux/amd64”).

Return Type
String !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 tool-version
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Go().
			Toolversion(ctx)
}
@function
async def example() -> str:
	return await (
		dag.go()
		.toolversion()
	)
@func()
async example(): Promise<string> {
	return dag
		.go()
		.toolVersion()
}

vet() 🔗

Vet runs go vet pkg against the supplied source. pkg defaults to ./.... Returns a non-nil error when vet reports any issue.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
pkgString !"./..."No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 vet --source DIR_PATH --pkg string
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory, pkg string)   {
	return dag.
			Go().
			Vet(ctx, source, pkg)
}
@function
async def example(source: dagger.Directory, pkg: str) -> None:
	return await (
		dag.go()
		.vet(source, pkg)
	)
@func()
async example(source: Directory, pkg: string): Promise<void> {
	return dag
		.go()
		.vet(source, pkg)
}

work() 🔗

Work runs go work <subcommand> [args...] against the supplied source and returns stdout. subcommand is required (e.g. “init”, “use”, “sync”, “version”).

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
subcommandString !-No description provided
args[String ! ] -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 work --source DIR_PATH --subcommand string
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory, subcommand string) string  {
	return dag.
			Go().
			Work(ctx, source, subcommand)
}
@function
async def example(source: dagger.Directory, subcommand: str) -> str:
	return await (
		dag.go()
		.work(source, subcommand)
	)
@func()
async example(source: Directory, subcommand: string): Promise<string> {
	return dag
		.go()
		.work(source, subcommand)
}

Ci 🔗

Ci is a chained builder for a standardized Go CI pipeline. Construct via Go.Ci(source); enable stages via the With* methods; call Run to execute checks-then-build, or Check to run only the parallel checks.

Stage 1 runs the enabled static checks in parallel (Fmt, Vet, Lint, Test); errors are aggregated. Stage 2 builds the source and Run returns the produced binary as a *dagger.File. Downstream consumers compose that file into their own pipelines (package, sign, publish, …).

check() 🔗

Check runs the enabled check stages (Fmt, Vet, Lint, Test) in parallel via github.com/dagger/dagger/util/parallel and returns the aggregated error. Use when callers want to run the checks independently of the build (for example multi-platform pipelines that share one check run across N platform builds).

Return Type
Void !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 check
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory)   {
	return dag.
			Go().
			Ci(source).
			Check(ctx)
}
@function
async def example(source: dagger.Directory) -> None:
	return await (
		dag.go()
		.ci(source)
		.check()
	)
@func()
async example(source: Directory): Promise<void> {
	return dag
		.go()
		.ci(source)
		.check()
}

run() 🔗

Run executes the pipeline: stage 1 (Check) → stage 2 (build). Returns the built binary as a *dagger.File. On stage-1 failure, returns the aggregated error from Check and a nil file (stage 2 is skipped).

Return Type
File !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 run
func (m *MyModule) Example(source *dagger.Directory) *dagger.File  {
	return dag.
			Go().
			Ci(source).
			Run()
}
@function
def example(source: dagger.Directory) -> dagger.File:
	return (
		dag.go()
		.ci(source)
		.run()
	)
@func()
example(source: Directory): File {
	return dag
		.go()
		.ci(source)
		.run()
}

withBuild() 🔗

WithBuild configures the build stage parameters. pkg defaults to “.” when empty; binaryName defaults to the basename of the module directive in go.mod when empty. Build is always executed by Run regardless of whether this method is called.

Note: the binary-name flag is called binaryName (CLI: –binary-name) to avoid colliding with Dagger CLI’s top-level –output/-o flag.

Return Type
Ci !
Arguments
NameTypeDefault ValueDescription
pkgString -No description provided
binaryNameString -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 with-build
func (m *MyModule) Example(source *dagger.Directory) *dagger.GoCi  {
	return dag.
			Go().
			Ci(source).
			Withbuild()
}
@function
def example(source: dagger.Directory) -> dagger.GoCi:
	return (
		dag.go()
		.ci(source)
		.withbuild()
	)
@func()
example(source: Directory): GoCi {
	return dag
		.go()
		.ci(source)
		.withBuild()
}

withFmt() 🔗

WithFmt enables the gofmt check stage.

Return Type
Ci !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 with-fmt
func (m *MyModule) Example(source *dagger.Directory) *dagger.GoCi  {
	return dag.
			Go().
			Ci(source).
			Withfmt()
}
@function
def example(source: dagger.Directory) -> dagger.GoCi:
	return (
		dag.go()
		.ci(source)
		.withfmt()
	)
@func()
example(source: Directory): GoCi {
	return dag
		.go()
		.ci(source)
		.withFmt()
}

withLint() 🔗

WithLint enables the golangci-lint check stage. version pins the installed golangci-lint version (defaults to defaultGolangciLintVersion when empty). config, if non-nil, is mounted at golangciLintConfigMountPath and passed to golangci-lint via –config.

Return Type
Ci !
Arguments
NameTypeDefault ValueDescription
versionString -No description provided
configFile -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 with-lint
func (m *MyModule) Example(source *dagger.Directory) *dagger.GoCi  {
	return dag.
			Go().
			Ci(source).
			Withlint()
}
@function
def example(source: dagger.Directory) -> dagger.GoCi:
	return (
		dag.go()
		.ci(source)
		.withlint()
	)
@func()
example(source: Directory): GoCi {
	return dag
		.go()
		.ci(source)
		.withLint()
}

withTest() 🔗

WithTest enables the go test ./... check stage. Pass race=true to enable the data-race detector.

Return Type
Ci !
Arguments
NameTypeDefault ValueDescription
raceBoolean -No description provided
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 with-test
func (m *MyModule) Example(source *dagger.Directory) *dagger.GoCi  {
	return dag.
			Go().
			Ci(source).
			Withtest()
}
@function
def example(source: dagger.Directory) -> dagger.GoCi:
	return (
		dag.go()
		.ci(source)
		.withtest()
	)
@func()
example(source: Directory): GoCi {
	return dag
		.go()
		.ci(source)
		.withTest()
}

withVet() 🔗

WithVet enables the go vet ./... check stage.

Return Type
Ci !
Example
dagger -m github.com/z5labs/devex/daggerverse/go@93616a322270189d6f9aa8985071fa6dd1f9282e call \
 ci --source DIR_PATH \
 with-vet
func (m *MyModule) Example(source *dagger.Directory) *dagger.GoCi  {
	return dag.
			Go().
			Ci(source).
			Withvet()
}
@function
def example(source: dagger.Directory) -> dagger.GoCi:
	return (
		dag.go()
		.ci(source)
		.withvet()
	)
@func()
example(source: Directory): GoCi {
	return dag
		.go()
		.ci(source)
		.withVet()
}