#How to pass flags when calling a function from a module using the dag client in code?

1 messages · Page 1 of 1 (latest)

dry herald
#

Take this backend build function:

// Returns the built binary for the Go source code
func (m *Backend) Build(
    // source code you want to built
    source *Directory,
    // os you want to build for
    // +optional
    // +default="linux"
    os string,
    // architecture you want to build for
    // +optional
    arch string) *File {
    if arch == "" {
        arch = runtime.GOARCH
    }
    return dag.Container().From("golang:latest").
        WithMountedDirectory("/src", source).
        WithWorkdir("/src").
        WithEnvVariable("GOOS", os).
        WithEnvVariable("GOARCH", arch).
        WithExec([]string{"go", "build", "-o", "greetings"}).
        File("/src/greetings")
}

If I'm calling this function from a parent module how do I pass in the os and arch flags? I understand how to do it with the CLI but not in code. I want to pass the os here:

backendBuild := dag.Backend().Build(source)

Thanks!

urban vale
#

There should be a struct generated that you can pass to Build - something like BackendBuildOpts

#

if you look at the generated function signature for Build, it'll be in there