Repository navigation
Go SDK: support modules own types being used as and with interfaces #12366
sipsma
started this conversation in
maintainers
Replies: 2 comments
|
+1 on this issue :) |
0 replies
|
I have the following use case... I have a builder module defined as follows: /// [email protected]/org/buildermodule/.dagger
type Task interface {
DaggerObject
Do(ctx context.Context) error
}
type Builder struct {
ExtraTasks []Task
}
func (b* Builder) WithExtraTask(extraTask Task) *Builder {
b.ExtraTasks = append(b.ExtraTasks, extraTask)
return b
}
func (b *Builder) Build(ctx context.Context) error {
// do normal build stuff
for _, t := range b.ExtraTasks {
if err := t.Do(ctx); err != nil {
return err
}
}
return nil
}Then I have module in a project repo which consumes the builder module: /// [email protected]/org/myrepo/.dagger
type MyRepo struct {}
func (r *MyRepo) Build() error {
return dag.BuilderModule().WithExtraTask((&ExtraTask{}).AsBuilderTask()).Build() // not possible
}
type ExtraTask struct {}
func (*ExtraTask) Do(ctx context.Context) error {
// .. extra task
}Unfortunately the above does not work as currently the /// [email protected]/org/myrepo/.dagger/main
type MyRepo struct {}
func (r *MyRepo) Build() error {
return dag.BuilderModule().WithExtraTask(dag.ExtraTask().AsBuilderTask()).Build()
}
/// [email protected]/org/main/.dagger/extratask
type ExtraTask struct {}
func (*ExtraTask) Do(ctx context.Context) error {
// .. extra task
}Would love to see this implemented as it would remove the need to have an extra module :) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Follow-up to #6254
Right now there's a fairly annoying limitation in that in Go modules it's not possible to use an object you've defined in your module to implement an interface you've defined in your module.
This is due to the fact that interfaces are passed by ID by right now objects defined in a module are still passed by raw json in the context of themselves (some previous discussion with more context on why here).
So to support this I think we'll probably just want to bite the bullet and deal with the complication of passing an object by id within the module it's defined in.
EDIT: another variation of the same sort of problem here came up: https://discord.com/channels/707636530424053791/1199101642260365432/1199110908639707186
Essentially, we also want interfaces defined in your own module to be implementable by any other types (whether from deps or your own types).
This in particular may actually call for blown self-API codegen, otherwise the module can't get codegen for the interfaces it has defined.
All reactions