You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently yaml.Marshal() & os.WriteFile() is used to write a Function configuration to disk. It is a convenient way to handle Golang structures, but it has one major drawback - we are unable to write comments to the file. Comments are useful as we can explain the fields, add examples, defaults etc. We can even write the whole configuration to the file, just comment the fields that are not used and users can easily uncomment them if they want to use them (for example the whole options part would benefit from this).
I have been thinking how to solve this for some time and there's option that could be potentially used - Golang built in templating from text/template package. Something like this:
typefuncTemplateDatastruct {
FunctionNamestringFunctionRuntimestringFunctionRegistrystringFunctionImagestringFunctionTypestring...
}
func (fFunction) Write() (errerror) {
funcYamlTemplate:=`specVersion: 0.35.0name: {{.FunctionName}}runtime: {{.FunctionRuntime}}registry: {{.FunctionRegistry}}image: {{.FunctionImage}}# my commentinvoke: {{.FunctionType}}# another Comment...`varfuncDatafuncTemplateData// this would set all the values that are set in the Function struct and fill defaults for the restfuncData=f.GetValuesOrDefaults()
tmpl, err:=template.New("func.yaml").Parse(funcYamlTemplate)
file, err:=os.Create(projectRoot+"func.yaml")
returntmpl.Execute(file, funcData)
}
To read the function config, we can use the same apporach we have now, we just need to change the write function. This solution is obviously much harder to implement (dealing with yamls this way is a pain). But it could give us the benefit of adding some comments&examples on the file. Obviously this apporach still doesn't allow users to write their own comments, but at least something. Or maybe it is now worth the work 🤷♂️
The text was updated successfully, but these errors were encountered:
This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.
Currently
yaml.Marshal()
&os.WriteFile()
is used to write a Function configuration to disk. It is a convenient way to handle Golang structures, but it has one major drawback - we are unable to write comments to the file. Comments are useful as we can explain the fields, add examples, defaults etc. We can even write the whole configuration to the file, just comment the fields that are not used and users can easily uncomment them if they want to use them (for example the whole options part would benefit from this).func/pkg/functions/function.go
Lines 367 to 388 in f671918
I have been thinking how to solve this for some time and there's option that could be potentially used - Golang built in templating from
text/template
package. Something like this:The same approach is used for Tekton Pipeline templates:
https://github.com/knative/func/blob/main/pkg/pipelines/tekton/templates_pack.go
https://github.com/knative/func/blob/main/pkg/pipelines/tekton/templates.go#L165
To read the function config, we can use the same apporach we have now, we just need to change the write function. This solution is obviously much harder to implement (dealing with yamls this way is a pain). But it could give us the benefit of adding some comments&examples on the file. Obviously this apporach still doesn't allow users to write their own comments, but at least something. Or maybe it is now worth the work 🤷♂️
The text was updated successfully, but these errors were encountered: