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
Name | Type | Default Value | Description |
---|---|---|---|
image | Container | - | 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. |
src | Directory ! | - | a path to a directory containing the source code |
Example
dagger -m github.com/purpleclay/daggerverse/golang@7e83bccc350fa981e975ac0c8619f92a1b729958 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
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
Name | Type | Default Value | Description |
---|---|---|---|
main | String | - | the path to the main.go file of the project |
out | String | - | the name of the built binary |
os | String | - | the target operating system |
arch | String | - | 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
Name | Type | Default Value | Description |
---|---|---|---|
short | Boolean | true | if only short running tests should be executed |
shuffle | Boolean | true | if the tests should be executed out of order |
run | String | - | run select tests only, defined using a regex |
skip | String | - | skip select tests, defined using a regex |
verbose | Boolean | - | 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
Name | Type | Default Value | Description |
---|---|---|---|
memory | Boolean | true | print memory allocation statistics for benchmarks |
time | String | "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
Name | Type | Default Value | Description |
---|---|---|---|
format | String | "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()
}