예를 들어 하나의 소스 파일에서 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}}`)
}
이 질문에 감사드립니다. 물론 그것은 문서에 있지만 자습서는 또한 당신이 그것에 대해 생각하지 않도록 권장합니다. 그리고 나서 당신이 그것을 알아 내야 할 때 당신은 파기를 원하지 않습니다. :) –