Skip to content

Added trim to available methods in template #123

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

Merged
merged 2 commits into from
Oct 9, 2015

Conversation

mariusGundersen
Copy link

it simply removes whitespace from the given string.

jwilder added a commit that referenced this pull request Oct 9, 2015
Added trim to available methods in template
@jwilder jwilder merged commit 7cbbda6 into nginx-proxy:master Oct 9, 2015
@jwilder
Copy link
Collaborator

jwilder commented Oct 9, 2015

Thanks @mariusGundersen!

@md5
Copy link
Contributor

md5 commented Oct 27, 2015

I ran into a problem with this in nginx-proxy/nginx-proxy@f394596

Since strings.TrimSpace strictly takes a string, it barfs if it gets passed an interface{}, even if it's actually a string.

I think it would be worthwhile to have some sort of stringToStringHelper function to use internally in docker-gen to take functions that are func(string) string and turn them into func(interface {}) string using reflection to check if the argument is actually a string or a *string. I could also see having other helpers like stringStringToStringHelper for the func(string,string) string case (and possibly others).

@jwilder
Copy link
Collaborator

jwilder commented Oct 27, 2015

Maybe all the template functions should just work with interface{} and return the original value if it's not a string?

@md5
Copy link
Contributor

md5 commented Oct 27, 2015

I think they should probably error out when they aren't given what they expect, but I think in general it's good for the functions to be flexible in the concrete types they accept as long as the reflected types are usable.

@jwilder
Copy link
Collaborator

jwilder commented Oct 27, 2015

Agreed. Looks like hugo does that for its functions: https://github.com/spf13/hugo/blob/master/tpl/template_funcs.go

@md5
Copy link
Contributor

md5 commented Oct 27, 2015

spf13/cast looks quite useful 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants