6

I'm having issues importing "golang.org/x/net/html" it's simply telling me it can't find the package. Looking around the internet has only confused me more with some people saying that you can't use it anymore, some people saying to do this: Install exp/html in Go and some people saying that just using "golang.org/x/net/html" works just fine.

Here is just a small part of the code I'm trying to run:

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
}

It obviously won't let me use the html token because I can't import the package.

Community
  • 1
  • 1
Elegant Metal
  • 139
  • 3
  • 8
  • Did you set the go path and go root ? If yes can you try go get -u golang.org/x/net/html – MIkCode May 25 '15 at 20:48
  • Just so I'm making sure I did it correctly, in eclipse I went to window->preferences->Go->then set my GOROOT to C:\Go is this correct? – Elegant Metal May 25 '15 at 20:56
  • 2
    Have you already `go get`-ed it? – icza May 25 '15 at 21:20
  • When it comes to using "go get code.google.com/p/go.net/html" I'm not quite sure how to use it. Putting it in the import doesn't work and I really don't understand where else I'm supposed to put it – Elegant Metal May 25 '15 at 21:35
  • Your import in your code is `golang.org/x/net/html`. This means you should be opening a Command Prompt/Terminal and typing: `go get golang.org/x/net/html` into there. Once you've done that, try building. – Simon Whitehead May 25 '15 at 23:04
  • 1
    Oh ok I see, however I'm getting the error message "cannot download, $GOPATH not set", so I must have not set up my path correctly : /. Sorry again for how silly this is. My programming experience outside visual studios is very small. After actually creating a path and trying to do the go get golang.org/x/net/html I ran into another issue: go: missing Git command.... Any ideas? – Elegant Metal May 26 '15 at 00:24
  • @ElegantMetal -- go workspace setup in brief: http://stackoverflow.com/questions/20628918/cannot-download-gopath-not-set/20629533#20629533 -- I'm not sure how you get git for Windows since I'm not on Windows, but https://msysgit.github.io/ is a top Google hit for it. – twotwotwo May 26 '15 at 01:51
  • (There is also https://git-scm.com/download/win -- but since I have no special insight into Git on Windows, probably not that useful for me to keep throwing things out there.) – twotwotwo May 26 '15 at 01:52

2 Answers2

3

You can execute at the command line “go get golang.org/x/net/html”

storm
  • 31
  • 1
  • package golang.org/x/net/html: unrecognized import path "golang.org/x/net/html": reading https://golang.org/x/net/html?go-get=1: 403 Forbidden – faza Apr 12 '22 at 14:30
2

You can take a look at https://golang.org/doc/code.html. It contains a very good description on how to start coding in Go. The issues you are mentioning are described there.

So, you set GOROOT to your installation path. Then you set GOPATH to your go workspace(s), which obey the bin, pkg, src structure. The first entry in your GOPATH is used to store the go get ... which you install on your machine.

Kiril
  • 6,009
  • 13
  • 57
  • 77