#Dynamically load and call a module

1 messages · Page 1 of 1 (latest)

slate plinth
#

Hi! I'm looking to dynamically load and call a module just to understand Dagger's internals a little better.

Something like

package main

import (
    "context"
    "os"

    "dagger.io/dagger"
)

// Intended use: `go run ./ path/to/my/module myFunction`
func main() {
    ctx := context.Background()

    dag, err := dagger.Connect(ctx)
    if err != nil {
        panic(err)
    }

    module := dag.Host().Directory(os.Args[1]).AsModule()

    // Load the module.

    // Call the function `os.Args[2]` on the module.
}
past arch
#

you won't have the generated bindings in dag.xxx() since that requires loading the module at build time. but you can make all the same queries dynamically

#

you can check out the contents of a module's generated dagger.gen.go and hand-write similar queries

slate plinth
#

This is perfect, thanks