【问题标题】:Golang import issueGolang 导入问题
【发布时间】:2015-05-25 20:30:25
【问题描述】:

我在导入“golang.org/x/net/html”时遇到问题,它只是告诉我找不到包。环顾互联网只是让我更加困惑,有些人说你不能再使用它了,有些人说这样做:Install exp/html in Go 还有一些人说只使用“golang.org/x/net/html”工作得很好。

这只是我尝试运行的代码的一小部分:

package main


import (
    "fmt"
    "html"
    "net/http"
    "golang.org/x/net/html"
    "os"
    "strings"
)

// Helper function to pull the href attribute from a Token
func getHref(t html.Token) (ok bool, href string) {
    // Iterate over all of the Token's attributes until we find an "href"
    for _, a := range t.Attr {
        if a.Key == "href" {
            href = a.Val
            ok = true
        }
    }

    return
}

它显然不会让我使用 html 令牌,因为我无法导入包。

【问题讨论】:

  • 你设置了 go path 并 go root 了吗?如果是,你可以试试 go get -u golang.org/x/net/html
  • 只是为了确保我做的正确,在 Eclipse 中我转到 window->preferences->Go->然后将我的 GOROOT 设置为 C:\Go 这是正确的吗?
  • 你已经go get-ed了吗?
  • 当谈到使用“go get code.google.com/p/go.net/html”时,我不太确定如何使用它。把它放在导入中不起作用,我真的不明白我应该把它放在哪里
  • 哦,好的,我明白了,但是我收到错误消息“无法下载,$GOPATH 未设置”,所以我一定没有正确设置路径:/。再次抱歉这是多么愚蠢。我在视觉工作室之外的编程经验非常少。在实际创建路径并尝试执行 go get golang.org/x/net/html 之后,我遇到了另一个问题:go: missing Git command....有什么想法吗?

标签: go


【解决方案1】:

你可以看看https://golang.org/doc/code.html。它包含关于如何开始在 Go 中编码的非常好的描述。您提到的问题在此处进行了描述。

因此,您将GOROOT 设置为您的安装路径。然后你将 GOPATH 设置为你的 go 工作空间,它遵循 bin, pkg, src 结构。 GOPATH 中的第一个条目用于存储您在计算机上安装的 go get ...

【讨论】:

    【解决方案2】:

    你可以在命令行执行 “go get golang.org/x/net/html”

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-17
    • 2013-03-02
    • 1970-01-01
    • 2021-10-23
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多