golang
A utility module for building, testing, and linting Go projectsInstallation
dagger install github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64Entrypoint
Return Type
Golang !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| ctr | Container | - | Specify an alternative container to index.docker.io/golang |
| source | Directory | - | The source directory of the Go project |
| version | String ! | "1.24" | Golang image tag to use |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version stringfunc (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@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string containerfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | The Go source code to build |
| args | [String ! ] ! | - | Arguments to `go build` |
| arch | String | - | The architecture for GOARCH |
| os | String | - | The operating system for GOOS |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string build --args string1 --args string2func (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | The Go source code to build |
| args | [String ! ] | - | Arguments to `go build` |
| arch | String | - | The architecture for GOARCH |
| os | String | - | The operating system for GOOS |
| base | Container | - | Base container in which to copy the build |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string build-containerfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | The Go source code to test |
| args | [String ! ] | - | Arguments to `go test` +default "./..." |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string testfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | The Go source code to format |
| args | [String ! ] | - | Arguments to `go fmt` +default "./..." |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string fmtfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | The Go source code to lint |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string golangci-lintfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory | - | The Go source code to lint |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string golangci-lint-fixfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| version | String ! | "1.24" | Golang image tag to use |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string base --version stringfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | No description provided |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string with-source --source DIR_PATHfunc (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@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string get-sourcefunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| ctr | Container ! | - | No description provided |
Example
dagger -m github.com/kpenfound/dagger-modules/golang@428ffe16f0a2e3c9e4d0d9debf6420db29d3cb64 call \
--version string with-container --ctr IMAGE:TAGfunc (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)
}