首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何导入和使用同名的不同包

如何导入和使用同名的不同包
EN

Stack Overflow用户
提问于 2012-05-02 14:18:42
回答 1查看 64.3K关注 0票数 161

例如,我想在一个源文件中同时使用text/template和html/template。但是下面的代码抛出了错误。

代码语言:javascript
复制
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}}`)

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-02 14:24:50

代码语言:javascript
复制
import (
    "text/template"
    htemplate "html/template" // this is now imported as htemplate
)

有关它的更多信息,请阅读in the spec

票数 293
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10408646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档