2015-05-25 71 views
4

我遇到導入「golang.org/x/net/html」的問題,它只是告訴我找不到包。環顧網絡只會讓一些人感到困惑,因爲有人說你不能再使用它了,有人說這樣做:Install exp/html in Go和一些人說只是使用「golang.org/x/net/html」只是工作精細。Golang導入問題

這裏是我試圖運行的代碼的一小部分:

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標記,因爲我不能導入包。

+0

你是否設置了去路和根?如果是的話,你可以嘗試去獲取-u golang.org/x/net/html – MIkCode

+0

就這樣我確保我做得正確,在eclipse中我去了window-> preferences-> Go->然後將我的GOROOT設置爲C:\ Go是否正確? –

+2

你已經'去'了嗎? – icza

回答

2

你可以看看https://golang.org/doc/code.html。它包含了關於如何在Go中開始編碼的非常好的描述。這裏提到你提到的問題。

因此,您將GOROOT設置爲您的安裝路徑。然後,您將GOPATH設置爲您的工作空間,它遵循bin, pkg, src結構。您的GOPATH中的第一個條目用於存儲您在機器上安裝的go get ...