#Is there some clever way to parse src

1 messages · Page 1 of 1 (latest)

boreal bronze
#

Somewhat important to this is that I'm calling

    pkgs, err := packages.Load(cfg, "./...")
    if err != nil {
        fmt.Fprintf(os.Stderr, "failed to load packages: %v\n", err)
        os.Exit(1)
    }

to match the order of files/commands that would be returned by go generate - so I can't just iterate file content from each dagger.File

silver cedar
#

You can expose your Go code as a Dagger Function directly, using the Go SDK. What would be the arguments to your function? A Directory?

boreal bronze
#

yeah function signature would look like this

func (m *mymodule) Generate(ctx context.Context, src *Directory) {
silver cedar
#

Assuming your function has a Directory, and wants to export it to its own local filesystem, inside the function's container, to call that packages.Load() function against, you can use Directory.Export. It will export to the filesystem of the current client - which is your own function

#
func (m *mymodule) Generate(ctx context.Context, src *Directory) {
  _ := src.Export("/tmp/src")
  os.Chdir("/tmp/src")
  pkgs, err := packages.Load(cfg, "./...")
    if err != nil {
        fmt.Fprintf(os.Stderr, "failed to load packages: %v\n", err)
        os.Exit(1)
    }
}
#

Checking with @potent eagle that I'm not saying anything stupid... 🙂

boreal bronze
#

Ah yeah that makes sense ok I'll give that a go

#

ty!

#

yeah that works. nice!