#Generated clients - no WithLogOutput?

1 messages · Page 1 of 1 (latest)

delicate venture
#

Trying out switching from dagger.io/dagger to a generated client. I used to have something like this in my code, which was quite nice. That ClientOpt is no longer there on the generated client. Is there a new approach for doing this ?

out := io.Discard
if verbose {
    out = os.Stderr
}
dag, err := dagger.Connect(ctx, dagger.WithLogOutput(out))
if err != nil {
    return fmt.Errorf("dagger connect: %w", err)
}
defer dag.Close()
#

ah ok, I'm realizing this is working a bit differently than I initially assumed. dagger in this example is internal/dagger (the generated client), but I can import daggersdk "dagger.io/dagger" to do this

#

but then my question is... if it's a generated client and I can call dagger.MyModule{}.MyFunction(), how would I do the equivalent of the above WithLogOutput usage there ?

#

Hm I see that in the generated dagger/dag, the log output and engine connect is hardcoded in the generated initClient() calls. I don't see an option to provide my own instance of dagger.Client 😦, which is what I think I need ?

delicate venture
#

Only way I can do it, is by chaning the generated dag package code:

func SetClient(c *dagger.Client) {
    clientMu.Lock()
    defer clientMu.Unlock()
    client = c
}

then as long as I call that before calling the generated function, it works:

// import (
//     "internal/dagger"
//     "internal/dagger/dag"
//     daggersdk "dagger.io/dagger"
// )
client, err := dagger.Connect(ctx, daggersdk.WithLogOutput(io.Discard))
if err != nil {
    return fmt.Errorf("dagger connect: %w", err)
}
defer client.Close()
dag.SetClient(client)
#

any reason why a setter like that shouldn't be part of the dag package ? Or (maybe better, but more intrusive) have the whole dag encapsulated in a struct that we need to initialize with e.g. dagger.NewDAG(*dagger.Client)

delicate venture
#

Ok I think I'm finally seeing the light. You don't have to use the global dag, the client , as long as it's created with "internal/dagger".Connect will have the generated functions as well.