Render Golang templates with a timeout
Reading Time: Approximately 2 minutes.Situation You’re writing a Go program that renders arbitrary Go templates that users can write. Since they are arbitrary, you want to prevent users from accidentally DDoSing your program by using long-running template functions. Something like this: import ( "os" "template" ) // Perhaps this is exposed through an interface that a // third-party API implements, for example. func LongRunningFunction(s string) { time.Sleep(100000000) // This takes forever return s } func main() { tmpl := `Hello, {{ . … »