pipeline/target: implement as variant types
Go doesn't really do variants, so we must somehow emulate it. The json objects we use are essentially tagged unions, with a `name` field in reverse domain name notation identifying the type and a type specific 'options' object. In Go we represent this by having an BarOptions interface, which implements a private method `isBarOptions()`, making sure that only types in the same package are able to implement it. Each type FooBar that should belong to the variant implements the interface, and a constructor `NewFooBar(options *FooBarOptions) *Bar` that makes sure the `name` field is set correctly. This would be enough to represent our types and marshal them into JSON, but unmarshalling would not work (json does not know about our tags, so would not know what concrete types to demarshal to). We therefore must also implement the Unmarshall interface for Bar, to select the right types for the Options field. We implement his logic for Target, Stage and Assembler. A handful of concrete types are also implemented, matching what osbuild supports. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
87bcd7f9d3
commit
7625d26ff5
17 changed files with 393 additions and 70 deletions
25
internal/pipeline/tar_assembler.go
Normal file
25
internal/pipeline/tar_assembler.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package pipeline
|
||||
|
||||
type TarAssemblerOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
Compression string `json:"compression,omitempty"`
|
||||
}
|
||||
|
||||
func (TarAssemblerOptions) isAssemblerOptions() {}
|
||||
|
||||
func NewTarAssemblerOptions(filename string) *TarAssemblerOptions {
|
||||
return &TarAssemblerOptions{
|
||||
Filename: filename,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTarAssembler(options *TarAssemblerOptions) *Assembler {
|
||||
return &Assembler{
|
||||
Name: "org.osbuild.tar",
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
|
||||
func (options *TarAssemblerOptions) SetCompression(compression string) {
|
||||
options.Compression = compression
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue