Custom Types
A Dagger Module can have multiple object types defined. It's important to understand that they are only accessible through chaining, starting from a function in the main object.
Here is an example of a function named DaggerOrganization
that returns a custom Organization
type, itself containing a collection of Account
types:
package main
type Github struct{}
func (module *Github) DaggerOrganization() *Organization {
return &Organization{
URL: "https://github.com/dagger",
Repositories: []*GitRepository{dag.Git(`${organization.url}/dagger`)},
Members: []*Account{
{"jane", "jane@example.com"},
{"john", "john@example.com"},
},
}
}
type Account struct {
Username string
Email string
}
func (account *Account) URL() string {
return "https://github.com/" + account.Username
}
type Organization struct {
URL string
Repositories []*GitRepository
Members []*Account
}
note
When the Dagger Engine extends the Dagger API schema with these types, it prefixes their names with the name of the main object:
- Github
- GithubAccount
- GithubOrganization
This is to prevent possible naming conflicts when loading multiple modules, which is reflected in code generation (for example, when using this module in another one as a dependency).
Here's an example of calling this module to get all member URLs:
dagger call dagger-organization members url
The result will be:
https://github.com/jane
https://github.com/john