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@v0.2.0

Entrypoint

Return Type
Golang !
Arguments
NameTypeDescription
baseContainer 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. `NOTE:` Any pre-existing entrypoint will be removed, in favour of raw `go` commands
srcDirectory !a path to a directory containing the source code
Example
dagger -m github.com/purpleclay/daggerverse/golang@be8e201f848e3bd5086ffa14a10aa151656d36b4 call \
 --src DIR_PATH
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. It expects the go.mod file to be located within the root of the project

Return Type
String !
Example
dagger -m github.com/purpleclay/daggerverse/golang@be8e201f848e3bd5086ffa14a10aa151656d36b4 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 binary from a Go project using the provided configuration

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
ldflags[String ! ] ["-s", "-w"]flags to configure the linking during a build, by default sets flags for generating a release binary
Example
dagger -m github.com/purpleclay/daggerverse/golang@be8e201f848e3bd5086ffa14a10aa151656d36b4 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
String !
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
Example
dagger -m github.com/purpleclay/daggerverse/golang@be8e201f848e3bd5086ffa14a10aa151656d36b4 call \
 --src DIR_PATH test
func (m *myModule) example(ctx context.Context, src *Directory) string  {
	return dag.
			Golang(src).
			Test(ctx)
}
@function
async def example(src: dagger.Directory) -> str:
	return await (
		dag.golang(src)
		.test()
	)
@func()
async example(src: Directory): Promise<string> {
	return dag
		.golang(src)
		.test()
}

bench() 🔗

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

Return Type
String !
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@be8e201f848e3bd5086ffa14a10aa151656d36b4 call \
 --src DIR_PATH bench
func (m *myModule) example(ctx context.Context, src *Directory) string  {
	return dag.
			Golang(src).
			Bench(ctx)
}
@function
async def example(src: dagger.Directory) -> str:
	return await (
		dag.golang(src)
		.bench()
	)
@func()
async example(src: Directory): Promise<string> {
	return dag
		.golang(src)
		.bench()
}

vulncheck() 🔗

Scans the target project for vulnerabilities using govulncheck

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

lint() 🔗

Lint the target project using golangci-lint

Return Type
String !
Arguments
NameTypeDefault ValueDescription
formatString "colored-line-number"the type of report that should be generated
Example
dagger -m github.com/purpleclay/daggerverse/golang@be8e201f848e3bd5086ffa14a10aa151656d36b4 call \
 --src DIR_PATH lint
func (m *myModule) example(ctx context.Context, src *Directory) string  {
	return dag.
			Golang(src).
			Lint(ctx)
}
@function
async def example(src: dagger.Directory) -> str:
	return await (
		dag.golang(src)
		.lint()
	)
@func()
async example(src: Directory): Promise<string> {
	return dag
		.golang(src)
		.lint()
}