News for hackers. Stuff that matters.
Re:Static files in Go by chewxy on Tuesday August 09, 2016 @09:11PM (#12258832)
Nothing is stopping you from doing something stupid like this though:

    func AtRuntime(writer io.Writer){
        templ := template.Must(template.New("blah").Parse(templateText))
        templ.Execute(writer, someStructhere)
    }
Though most sane devs would put the template parsing code in init()
Re:Static files in Go by leetrout on Tuesday August 09, 2016 @09:19PM (#12258865)
This brings up another question...

Couldn't you just put them in the global namespace in the package? I also don't see the need for init since this is just parsing / compiling a template one time. Maybe I'm just not a sane dev? I just put all my template and regex "must" statements as global vars in my package close to where they're used.

Re:Static files in Go by randomdata on Tuesday August 09, 2016 @09:45PM (#12258980)
Most definitely, if you want the compiled template loaded for the life of the application, at least. The documentation for template.Must says it is intended to be used exactly like that. If you were in a regular code block, you would check the error and handle it more gracefully.