DEV Community

Discussion on: GoLang Templating

Collapse
 
12mohaned profile image
mohaned mashaly • Edited

Thank you, I fixed them

Collapse
 
sennasemakula profile image
Senna • Edited

Nice. One more thing is that are you sure you want to execute the template when the error is not equal to nil? Shouldn't you move that outside the condition and replace it with a error log

That way you'll only try to execute the template if your html file correctly loaded

Thread Thread
 
12mohaned profile image
mohaned mashaly • Edited

the first version was right I reverted the changes, If your question is how you're not going to handle the exception if there's an error, well It depends, if you're using this in a production environment or a user is going to interact with application you must add an else statement which shows to the user an error happened or output a user friendly message or you will provide a bad user experience for the user, but since the tutorial focused on Golang Templating I didn't bother trying to deal with exceptions, but of-course it would be more convenient to add something like this in case you're dealing with a user
for example you can add log.fatal(err) also this won't be user friendly it will be for you as a developer to know what is the error.
Hope this answers your question

Thread Thread
 
sennasemakula profile image
Senna • Edited

You must have changed the code because I was referring to when you had:

if (err != nil) {
t.Execute(...)
}

I can see you have fixed this now.