#So I deleted the project and redid a

1 messages ยท Page 1 of 1 (latest)

loud depot
#

after dagger mod init
step 0

package main

import (
    "context"
)

type GoVersion struct {}

func (m *GoVersion) MyFunction(ctx context.Context, stringArg string) (*Container, error) {
    return dag.Container().From("alpine:latest").WithExec([]string{"echo", stringArg}).Sync(ctx)
}
#

adding more funcs
step 1a

package main

import (
    "context"
    "golang.org/x/mod/modfile"
)

type GoVersion struct {}

func (m *GoVersion) MyFunction(ctx context.Context, stringArg string) (*Container, error) {
    return dag.Container().From("alpine:latest").WithExec([]string{"echo", stringArg}).Sync(ctx)
}

func (m *GoVersion) Version(ctx context.Context) (string) {
    goMod, err := dag.Host().Directory(".").File("go.mod").Contents(ctx)
    if err != nil {
        panic(err)
    }
    f, err := modfile.Parse("go.mod", []byte(goMod), nil)
    if err != nil {
        panic(err)
    }
    return f.Go.Version
}
#

step 1b dagger mod sync ๐Ÿ‘

#

then remove extraneous
step 2a

#
package main

import (
    "context"
    "golang.org/x/mod/modfile"
)

type GoVersion struct {}

func (m *GoVersion) Version(ctx context.Context) (string) {
    goMod, err := dag.Host().Directory(".").File("go.mod").Contents(ctx)
    if err != nil {
        panic(err)
    }
    f, err := modfile.Parse("go.mod", []byte(goMod), nil)
    if err != nil {
        panic(err)
    }
    return f.Go.Version
}
#

step 2b dagger mod sync ๐Ÿ‘

#

but can't go straight to step 2 ๐Ÿ‘† after a dagger mod init