Skip to content

Go SDK: support modules own types being used as and with interfaces #6366

Closed

Description

@sipsma

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.

Activity

  1. changed the title [-]Go SDK: support objects from a user's module being passed as interface values[/-] [+]Go SDK: support modules own types being used as and with interfaces[/+] on Jan 22, 2024
  2. chrisjpalmer commented on May 12, 2025

    @chrisjpalmer
    Contributor

    +1 on this issue :)

  3. chrisjpalmer commented on May 12, 2025

    @chrisjpalmer
    Contributor

    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 .AsBuilderTask() method is not generated for this type. Currently I get around this like so:

    /// [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 :)

  4. locked and limited conversation to collaborators on Mar 24, 2026
  5. converted this issue into a discussion #12366 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions