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

How about adding casting option for <%= ? #19

Open
shkim opened this issue May 13, 2017 · 2 comments
Open

How about adding casting option for <%= ? #19

shkim opened this issue May 13, 2017 · 2 comments

Comments

@shkim
Copy link

shkim commented May 13, 2017

In some cases, I pass many variables via map[string]interface{}
A string can be printed with <%=v model["errorMsg"] %>
and hero will generate:
hero.EscapeHTML(fmt.Sprintf("%v", model["errorMsg"]), _buffer)

I think it would be handy if there is a casting option so here can generate the code like:
hero.EscapeHTML(model["errorMsg"].(string), _buffer)

@shkim
Copy link
Author

shkim commented May 13, 2017

I thought I could cast by myself, like:
<%= model["errorMsg"].(string) %>

but if model["errorMsg"] is nil, panic occurs.
So I hope casting is done only if the object is not nil in generated code.

@shiyanhui
Copy link
Owner

shiyanhui commented May 15, 2017

Sorry for replying late.

The error handler will be left to the user cause I can't think out a better way than that.

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

No branches or pull requests

2 participants