2019-02-23 17:29
浏览 220


I'm using "html" and "" in golang.

enter image description here

It's got error by same name.So I named other name like this.

net_html ""

and also I tried like this

_ ""

But it wasn't effect for me.

Do you know how to solve this problem?

图片转代码服务由CSDN问答提供 功能建议

我在golang中使用了“ html”和“”。








  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanbo7517 2019-02-23 19:34

    Using _ "" you import the package but you cut-off all access to it, this is used only when you need the imported package to perform some initialization and nothing else.

    Using net_html "" is ok and is exactly what you should do in this case. If you're still getting the "html redeclared as imported package ..." error then there might be an issue with the IDE you are using, but generally the Go compiler will not complain and your code should run without problems.

    To see for yourself that it works in a normal environment go to the following link and try running the program and you'll see that it compiles and executes.

    And here's a version with the same kind of error as the one that you're getting.

    So if net_html "" doesn't fix the "html redeclared as imported package ..." error, then try providing more info about your environment, like what IDE you're using, what version of Go you've installed, etc.

    点赞 打赏 评论
  • dongsaoshuo4326 2019-02-24 00:53

    When you use multiple package with same name, as you've experienced, Go will complain that the imported package name has been declared before.

    To avoid this issue, you have to import the package with custom PackageName like this :

    import (
        xhtml ""

    Then you can use public methods and structs from by accessing it via xhtml like this :

    package main
    import (
        xhtml ""
    func main() {
        // this will use `html` package
        htmlEscape := html.EscapeString("< &")
        // and this will use `` package
        xHtmlEscape := xhtml.EscapeString("< &")

    For more detail, you might want to check the Go spec.

    点赞 打赏 评论

相关推荐 更多相似问题