Dagger
Search

golang

A utility module for building, testing, and linting Go projects

Installation

dagger install github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654

Entrypoint

Return Type
Golang !
Arguments
NameTypeDefault ValueDescription
ctrContainer -Specify an alternative container to index.docker.io/golang
sourceDirectory -The source directory of the Go project
versionString !"1.24"Golang image tag to use
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string
func (m *MyModule) Example(version string) *dagger.Golang  {
	return dag.
			Golang(version)
}
@function
def example(version: str) -> dagger.Golang:
	return (
		dag.golang(version)
	)
@func()
example(version: string): Golang {
	return dag
		.golang(version)
}

Types

Golang 🔗

container() 🔗

Golang container with the go project and go toolchain

Return Type
Container !
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string container
func (m *MyModule) Example(version string) *dagger.Container  {
	return dag.
			Golang(version).
			Container()
}
@function
def example(version: str) -> dagger.Container:
	return (
		dag.golang(version)
		.container()
	)
@func()
example(version: string): Container {
	return dag
		.golang(version)
		.container()
}

build() 🔗

Build the Go project

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -The Go source code to build
args[String ! ] !-Arguments to `go build`
archString -The architecture for GOARCH
osString -The operating system for GOOS
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string build --args string1 --args string2
func (m *MyModule) Example(version string, args []string) *dagger.Directory  {
	return dag.
			Golang(version).
			Build(args)
}
@function
def example(version: str, args: List[str]) -> dagger.Directory:
	return (
		dag.golang(version)
		.build(args)
	)
@func()
example(version: string, args: string[]): Directory {
	return dag
		.golang(version)
		.build(args)
}

buildContainer() 🔗

Build a Go project returning a Container containing the build

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -The Go source code to build
args[String ! ] -Arguments to `go build`
archString -The architecture for GOARCH
osString -The operating system for GOOS
baseContainer -Base container in which to copy the build
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string build-container
func (m *MyModule) Example(version string) *dagger.Container  {
	return dag.
			Golang(version).
			BuildContainer()
}
@function
def example(version: str) -> dagger.Container:
	return (
		dag.golang(version)
		.build_container()
	)
@func()
example(version: string): Container {
	return dag
		.golang(version)
		.buildContainer()
}

test() 🔗

Test the Go project

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -The Go source code to test
args[String ! ] -Arguments to `go test` +default "./..."
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string test
func (m *MyModule) Example(ctx context.Context, version string) string  {
	return dag.
			Golang(version).
			Test(ctx)
}
@function
async def example(version: str) -> str:
	return await (
		dag.golang(version)
		.test()
	)
@func()
async example(version: string): Promise<string> {
	return dag
		.golang(version)
		.test()
}

fmt() 🔗

Format the Go project

Return Type
Golang !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -The Go source code to format
args[String ! ] -Arguments to `go fmt` +default "./..."
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string fmt
func (m *MyModule) Example(version string) *dagger.Golang  {
	return dag.
			Golang(version).
			Fmt()
}
@function
def example(version: str) -> dagger.Golang:
	return (
		dag.golang(version)
		.fmt()
	)
@func()
example(version: string): Golang {
	return dag
		.golang(version)
		.fmt()
}

golangciLint() 🔗

Lint the Go project

Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -The Go source code to lint
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string golangci-lint
func (m *MyModule) Example(ctx context.Context, version string) string  {
	return dag.
			Golang(version).
			GolangciLint(ctx)
}
@function
async def example(version: str) -> str:
	return await (
		dag.golang(version)
		.golangci_lint()
	)
@func()
async example(version: string): Promise<string> {
	return dag
		.golang(version)
		.golangciLint()
}

golangciLintFix() 🔗

Lint the Go project and apply fixes

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -The Go source code to lint
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string golangci-lint-fix
func (m *MyModule) Example(version string) *dagger.Directory  {
	return dag.
			Golang(version).
			GolangciLintFix()
}
@function
def example(version: str) -> dagger.Directory:
	return (
		dag.golang(version)
		.golangci_lint_fix()
	)
@func()
example(version: string): Directory {
	return dag
		.golang(version)
		.golangciLintFix()
}

base() 🔗

Sets up the Container with a golang image and cache volumes

Return Type
Golang !
Arguments
NameTypeDefault ValueDescription
versionString !"1.24"Golang image tag to use
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string base --version string
func (m *MyModule) Example(version string, version1 string) *dagger.Golang  {
	return dag.
			Golang(version).
			Base(version1)
}
@function
def example(version: str, version1: str) -> dagger.Golang:
	return (
		dag.golang(version)
		.base(version1)
	)
@func()
example(version: string, version1: string): Golang {
	return dag
		.golang(version)
		.base(version1)
}

withSource() 🔗

Specify the Source to use in the module

Return Type
Golang !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-No description provided
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string with-source --source DIR_PATH
func (m *MyModule) Example(version string, source *dagger.Directory) *dagger.Golang  {
	return dag.
			Golang(version).
			WithSource(source)
}
@function
def example(version: str, source: dagger.Directory) -> dagger.Golang:
	return (
		dag.golang(version)
		.with_source(source)
	)
@func()
example(version: string, source: Directory): Golang {
	return dag
		.golang(version)
		.withSource(source)
}

getSource() 🔗

Get the current state of the source directory

Return Type
Directory !
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string get-source
func (m *MyModule) Example(version string) *dagger.Directory  {
	return dag.
			Golang(version).
			GetSource()
}
@function
def example(version: str) -> dagger.Directory:
	return (
		dag.golang(version)
		.get_source()
	)
@func()
example(version: string): Directory {
	return dag
		.golang(version)
		.getSource()
}

withContainer() 🔗

Bring your own container

Return Type
Golang !
Arguments
NameTypeDefault ValueDescription
ctrContainer !-No description provided
Example
dagger -m github.com/kpenfound/dagger-modules/golang@f7964245d0146dd3810f247c6c09eb33518d4654 call \
 --version string with-container --ctr IMAGE:TAG
func (m *MyModule) Example(version string, ctr *dagger.Container) *dagger.Golang  {
	return dag.
			Golang(version).
			WithContainer(ctr)
}
@function
def example(version: str, ctr: dagger.Container) -> dagger.Golang:
	return (
		dag.golang(version)
		.with_container(ctr)
	)
@func()
example(version: string, ctr: Container): Golang {
	return dag
		.golang(version)
		.withContainer(ctr)
}