Elegant Metal
Elegant Metal

Reputation: 139

Golang import issue

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.

Upvotes: 6

Views: 10074

Answers (2)

storm
storm

Reputation: 31

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

Upvotes: 3

Kiril
Kiril

Reputation: 6219

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.

Upvotes: 2

Related Questions