Brian Voelker
Brian Voelker

Reputation: 859

golang variable setting

I need to set a variable at the beginning of my package that will later on be populated with parseFiles() but im not sure how to set the variable considering its not a string or int or anything generic like that. How would i set the variable without having to add some arbitrary name in there just to set it?

var templatefiles = template.New("foo") // Im having to do New("foo") just to set the variable

// Later on adding files to original variable
templatefiles.New("template name").Parse("Template text here")

Upvotes: 3

Views: 1859

Answers (1)

Stephen Weinberg
Stephen Weinberg

Reputation: 53488

You just need to replace = template.New("foo") with the type returned. In this case:

var templatefiles *template.Template // the return type of html/template.New()

templatefiles is now a global variable that contains a nil pointer to a type template.Template.

Upvotes: 5

Related Questions