简体   繁体   中英

Can't `go get` offline tutorial

I am trying to run the command go get golang.org/x/tour tour but I am getting the error message "package tour: unrecognized import path "tour" (import path does not begin with hostname)" . I also do not get the binary in my bin folder that is mentioned.

Things I have attempted to resolve the issue:

  • Read the documentation at https://golang.org/doc/code.html and https://golang.org/doc/install .
  • Verify workspace folders exist as specified in documentation (my workspace is /home/USERNAME/go , and inside that I have created 2 folders src and bin ).
  • changed command from go get golang.org/x/tour tour to go get golang.org/x/tour /home/USERNAME/go (still get a simillar import path error message)
  • verified that my go path is set correctly and go is installed using defaults, my go path in /etc/profile is /usr/local/go/bin
  • since the command did create a directory called golang.org , I navigated to /home/USERNAME/go/src/golang.org/x/tour and ran go build tour.go . I got the errors:

     # command-line-arguments ./tour.go:62:4: undefined: socketAddr ./tour.go:126:28: undefined: prepContent
  • read the README.md in the golang.org/x/tour folder

  • change bin permissions to 755

Syntax of go get is (run go help get to see):

usage: go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]

Everything you list at the end are all packages to get. So you should simply run:

go get golang.org/x/tour

Note: there is no need to pass an additional tour parameter. This is what the error message tells you: the tour package is not recognized.

The above command will get the golang.org/x/tour and install it into your $GOPATH/bin , so you can simply run it after the above command like:

$GOPATH/bin/tour

After go get golang.org/x/tour

Run go build

This will generate executable which on run start local tour at http://127.0.0.1:3999/

For me simply running the tour command worked fine , command-line output as follows !

C:\Users\ilife\go\src\golang.org\x\tour>tour
2020/05/23 20:04:39 Serving content from C:\Users\ilife\go\src\golang.org\x\tour
2020/05/23 20:04:39 A browser window should open. If not, please visit http://127.0.0.1:3999
2020/05/23 20:04:46 accepting connection from: 127.0.0.1:52660 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM