2
我需要在我的包的開始處設置一個變量,稍後將用parseFiles()填充,但我不知道如何設置該變量,因爲它不是一個字符串或int或任何泛型類似的變量。我如何設置變量,而不必在那裏添加一些任意名稱來設置它?golang變量設置
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")
工作感謝!!!如果後來我想清除變量呢?基本上清空var templatefiles中的模板? –
與任何指針一樣,您將其設置爲零。 'templatefiles = nil' –
對不起,我錯了,它沒有工作。這是我得到的錯誤。 http://play.golang.org/p/a0irFLNgpo –