-
Notifications
You must be signed in to change notification settings - Fork 81
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
ExecFuncStringWithErr will not panick when f call returns error #19
Conversation
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.
Could you also substitute function bodies for already existing ExecuteFuncString
functions with the corresponding calls to ExecuteFuncStingWithErr
?
template.go
Outdated
@@ -285,6 +309,26 @@ func (t *Template) ExecuteFuncString(f TagFunc) string { | |||
return s | |||
} | |||
|
|||
// ExecuteFuncString calls f on each template tag (placeholder) occurrence |
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.
ExecuteFuncString -> ExecuteFuncStringWithErr
You mean making the existing |
No, I mean calling |
Oh, I get it! |
@valyala Done |
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
@caibirdme , thanks for the contribution! |
ExecFuncString will panic if f call returns an error. But panic isn't a good choice, why not just return that error to user? To avoid unexpected panic, user must recover before calling ExecFuncString, this is a hidden requirement to call ExecFuncString.
For the sake of not breaking the compatibility, I added two new method called ExecFuncStringWithErr, which will not panic when f get an error, just returns an empty string and that error directly