Dagger
Search

golang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Installation

dagger install github.com/purpleclay/daggerverse/golang@v0.1.0

Entrypoint

Return Type
Golang !
Arguments
NameTypeDescription
imageContainer a custom base image containing an installation of golang
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 function

modVersion() 🔗

Echoes the version of go used by a target project

Return Type
String !
Example
dagger -m github.com/purpleclay/daggerverse/golang@4675abf5a511c33f41b15028fcd9e2f6d961691d 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@4675abf5a511c33f41b15028fcd9e2f6d961691d 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@4675abf5a511c33f41b15028fcd9e2f6d961691d 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@4675abf5a511c33f41b15028fcd9e2f6d961691d 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
Directory !
Example
dagger -m github.com/purpleclay/daggerverse/golang@4675abf5a511c33f41b15028fcd9e2f6d961691d call \
 --src DIR_PATH vulncheck
func (m *myModule) example(src *Directory) *Directory  {
	return dag.
			Golang(src).
			Vulncheck()
}
@function
def example(src: dagger.Directory) -> dagger.Directory:
	return (
		dag.golang(src)
		.vulncheck()
	)
@func()
example(src: Directory): Directory {
	return dag
		.golang(src)
		.vulncheck()
}