Skip to content
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

text/template: consider broadening the set of built-in template funcs #15007

Open
adg opened this issue Mar 29, 2016 · 2 comments
Open

text/template: consider broadening the set of built-in template funcs #15007

adg opened this issue Mar 29, 2016 · 2 comments
Milestone

Comments

@adg
Copy link
Contributor

@adg adg commented Mar 29, 2016

Some programs expect their users to write templates. One of these programs is docker-gen, and one of its users filed issue #14992 as they found the template language too restrictive for what they were trying to do.

As it happened, docker-gen provided the a template function to let the user do what they wanted (filter a set of structs based on the value of a field, and print something different if no structs with that field set to that specific value are found). That function is documented by the docker-gen README:

where $items $fieldPath $value: Filters an array or slice based on the values of a field path expression $fieldPath. A field path expression is a dot-delimited list of map keys or struct member names specifying the path from container to a nested value. Returns an array of items having that value.

The docker-gen program provides many such functions (see the README for the full list). Some of them are specific to docker-gen's purpose, but many of them are general purpose (such as where above).

Should we add some of these functions (or functions with similar behavior) to the built in set of template functions?

cc @robpike @bradfitz @Jonast

@robpike

This comment has been minimized.

Copy link
Contributor

@robpike robpike commented Mar 29, 2016

Counterproposal: collect some and put them in a separate but well-curated external repository.

@etc0de

This comment has been minimized.

Copy link

@etc0de etc0de commented Mar 30, 2016

For what it's worth, I got my info about templating from here: https://golang.org/pkg/text/template/
So whereever the actual code is added, it might be helpful if a mention of some sort would be added on that page (e.g. a link to the documentation of that additional package or something)

@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2016
@adg adg removed their assignment Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.