例如,我想在一个源文件中同时使用text/template和html/template。 但下面的代码会抛出错误。如何在Go语言中导入和使用不同的同名软件包?
import (
"fmt"
"net/http"
"text/template" // template redeclared as imported package name
"html/template" // template redeclared as imported package name
)
func handler_html(w http.ResponseWriter, r *http.Request) {
t_html, err := html.template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
t_text, err := text.template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
}
谢谢你提出这个问题。确定它在文档中,但教程也鼓励你不要去想它,然后当你需要弄明白时,你不想挖。 :) –