-
Notifications
You must be signed in to change notification settings - Fork 128
feat: add extensible transform API for custom field transformations #808
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
feat: add extensible transform API for custom field transformations #808
Conversation
b916851
to
ec2c08a
Compare
transform/defaults.go
Outdated
var DefaultValues = map[tree.Path]TransformFunc{} | ||
|
||
// For backward compatibility | ||
var defaultValues = DefaultValues |
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.
not needed, as a non-public field there's no backward compatibility to be addressed here
transform/defaults.go
Outdated
@@ -30,6 +34,20 @@ func init() { | |||
defaultValues["services.*.gpus.*"] = deviceRequestDefaults | |||
} | |||
|
|||
// RegisterDefaultTransformer registers a custom transformer for the given path pattern | |||
func RegisterDefaultTransformer(path string, transformer TransformFunc) { |
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.
RegisterDefaultTransformer
sounds weird to me. What about RegisterDefaultValue
transform/defaults.go
Outdated
} | ||
|
||
// GetDefaultTransformers returns a copy of the current default transformers | ||
func GetDefaultTransformers() map[string]TransformFunc { |
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.
why have this function while DefaultValues
is public ?
Can you please squash your commits, rebase and sign-off, so we can merge ? |
af372c9
to
6bf03b7
Compare
Hey @ndeloof
|
seems you included way more than the expected changes in your commit :') |
I see,It seems something broke after I rebased main |
d981d63
to
de3bbc1
Compare
@ndeloof fixed |
transform/canonical.go
Outdated
// TransformFunc is a function that can transform data at a specific path | ||
type TransformFunc func(data any, p tree.Path, ignoreParseError bool) (any, error) | ||
|
||
// For backward compatibility |
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.
unnecessary
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.
removed
de3bbc1
to
dade8b5
Compare
Head branch was pushed to by a user without write access
c153775
to
cc0c190
Compare
Linter complains about "stuttering" when using type as I refactored some naming: |
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.
Sounds good!
I wonder if we should not add a test, to avoid breaking change on the feature and give an exemple for developers who want to use it, WDYT?
c22999a
to
79a2dfe
Compare
Yes, I think that's a good idea I added a test and an example function |
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.
LGTM, thanks a lot for this contribution 🙏
Signed-off-by: Evgenii Orlov <[email protected]>
dd88e9a
to
3aed6c5
Compare
This enables users to extend compose-go with custom protocols and validation logic without forking the project, addressing the need for custom port protocols like http/https and domain name support
example:
Related issue: psviderski/uncloud#44