-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bake: prototype for composable bake attributes #2758
base: master
Are you sure you want to change the base?
Conversation
Very incomplete first draft. This requires some changes to the The only changes to |
bake/types.go
Outdated
// ParseExports expects that format and it's easier to do that then reimplement it | ||
// in multiple locations. | ||
var sb strings.Builder | ||
for name, val := range conv.AsValueMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't encode objects to csv
string. That is backwards as the (typed) object is what we need.
If you want to reduce duplication then there can be generic csv -> map[k]v
convert and then map to struct, although not sure if worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the prototype so the map[k]v
version is the canonical form.
To reduce duplication, I've created a separate ExportEntry
type with the same attributes. This type will implement encoding.TextUnmarshaler
and json.Unmarshaler
to control the marshaling and unmarshaling process in a consistent way. The type also has a ToPB()
method to convert the type to the controller API version.
The csv parsing has been extracted into UnmarshalText
and the original ParseExports
method has been changed to be a loop that does this:
var out ExportEntry
if err := out.UnmarshalText([]byte(s)); err != nil {
return nil, err
}
outs = append(outs, out.ToPB())
The a FromCtyValue
method has been created so we can still detect it. But, we now only need one implementation that uses UnmarshalText
and JSON unmarshaling and we should be able to reuse this implementation for each of these types.
611d320
to
2a36f74
Compare
This allows using either the csv syntax or a map to specify certain attributes.
2a36f74
to
88ff1f4
Compare
This allows using either the csv syntax or a map to specify certain attributes.