Dagger
Search

golang

A collection of functions for building, testing, linting and scanning your Go project for vulnerabilities.

Installation

dagger install github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958

Entrypoint

Return Type
Golang !
Arguments
NameTypeDescription
imageContainer A custom base image containing an installation of golang. If no image is provided, one is resolved based on the Go version defined within the projects go.mod file. The official Go image is pulled from DockerHub using either the bullseye (< 1.20) or bookworm (> 1.20) variants.
srcDirectory !a path to a directory containing the source code
Example
func (m *myModule) example(src *Directory) *Golang  {
	return dag.
			Golang(src)
}
@function
def example(src: dagger.Directory) -> dag.Golang:
	return (
		dag.golang(src)
	)
@func()
example(src: Directory): Golang {
	return dag
		.golang(src)
}

Types

Golang

Golang dagger module

modVersion()

Echoes the version of go defined within a projects go.mod file

Return Type
String !
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 call \
 --src DIR_PATH mod-version
func (m *myModule) example(ctx context.Context, src *Directory) string  {
	return dag.
			Golang(src).
			ModVersion(ctx)
}
@function
async def example(src: dagger.Directory) -> str:
	return await (
		dag.golang(src)
		.mod_version()
	)
@func()
async example(src: Directory): Promise<string> {
	return dag
		.golang(src)
		.modVersion()
}

build()

Build a static release binary without debug information or symbols

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
mainString -the path to the main.go file of the project
outString -the name of the built binary
osString -the target operating system
archString -the target architecture
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 call \
 --src DIR_PATH build
func (m *myModule) example(src *Directory) *Directory  {
	return dag.
			Golang(src).
			Build()
}
@function
def example(src: dagger.Directory) -> dagger.Directory:
	return (
		dag.golang(src)
		.build()
	)
@func()
example(src: Directory): Directory {
	return dag
		.golang(src)
		.build()
}

test()

Execute tests defined within the target project, ignores benchmarks by default

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
shortBoolean trueif only short running tests should be executed
shuffleBoolean trueif the tests should be executed out of order
runString -run select tests only, defined using a regex
skipString -skip select tests, defined using a regex
verboseBoolean -log all output from tests even if there are successful
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 call \
 --src DIR_PATH test
func (m *myModule) example(src *Directory) *Directory  {
	return dag.
			Golang(src).
			Test()
}
@function
def example(src: dagger.Directory) -> dagger.Directory:
	return (
		dag.golang(src)
		.test()
	)
@func()
example(src: Directory): Directory {
	return dag
		.golang(src)
		.test()
}

bench()

Execute benchmarks defined within the target project, excludes all other tests

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
memoryBoolean trueprint memory allocation statistics for benchmarks
timeString "5s"the time.Duration each benchmark should run for
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 call \
 --src DIR_PATH bench
func (m *myModule) example(src *Directory) *Directory  {
	return dag.
			Golang(src).
			Bench()
}
@function
def example(src: dagger.Directory) -> dagger.Directory:
	return (
		dag.golang(src)
		.bench()
	)
@func()
example(src: Directory): Directory {
	return dag
		.golang(src)
		.bench()
}

vulncheck()

Scans the target project for vulnerabilities using govulncheck

Return Type
File !
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 call \
 --src DIR_PATH vulncheck
func (m *myModule) example(src *Directory) *File  {
	return dag.
			Golang(src).
			Vulncheck()
}
@function
def example(src: dagger.Directory) -> dagger.File:
	return (
		dag.golang(src)
		.vulncheck()
	)
@func()
example(src: Directory): File {
	return dag
		.golang(src)
		.vulncheck()
}

lint()

Lint the target project using golangci-lint

Return Type
File !
Arguments
NameTypeDefault ValueDescription
formatString "colored-line-number"the type of report that should be generated
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 call \
 --src DIR_PATH lint
func (m *myModule) example(src *Directory) *File  {
	return dag.
			Golang(src).
			Lint()
}
@function
def example(src: dagger.Directory) -> dagger.File:
	return (
		dag.golang(src)
		.lint()
	)
@func()
example(src: Directory): File {
	return dag
		.golang(src)
		.lint()
}