Build documentation for Go 1 on Windows - windows

How to build Go 1 documentations on Windows?
It is at D:\go\doc on my machine and all links and paths are broken.

I'm not a master on Windows, but Go's documentation does not work like that. You should use godoc command for accessing Go documentation. Run godoc -http=:6060 and access documentation at http://127.0.0.1:6060 in your browser.

Related

How to use godoc for documentation

In one of my classes we have to use godoc to document our Go code. The code that we are using for the class is from a GitHub repo that we had to fork to our repo. Then from our repo I cloned it to a local repo. Every time I try to create the documentation using
godoc -http=:6060 &
it won't update. Is it because it was forked from someone else repo? I was under the belief that it would document the local repo.
Is this project a go module and you placed it outside of GOPATH? If so, that's probable that you have old version of godoc installed, that doesn't support go modules.
Module support for godoc was added only recently. You can install newest version by running go get -u golang.org/x/tools/cmd/godoc. Then, make sure to run godoc executable from GOBIN(by default it's set to $GOROOT/bin).
Is the code exporting any functions? (public functions names start with a capital letter)
If your code is not exporting any functions you will not see the documentation being shown because the idea for godoc is to show the functions that can be used by others.

Equivalent of python "help()" in go?

what is the equivalent of python "help()" in go? , how I can get help about modules?
Official documentation:
Latest HTML documentation for modules on golang.org
Run go help modules for more about modules. (This is the main entry point for modules topics via go help)
Run go help mod for more about the go mod command.
Run go help module-get for more about the behavior of go get when in module-aware mode.
Run go help goproxy for more about the module proxy, including a pure file-based option via a file:/// URL.
From the GitHub of Golang: https://github.com/golang/go/wiki/Modules

HTTP request in Dialplan

How would I go about preforming a HTTP GET request in the dialplan to send data to another system. I have done this in asterisks using curl. I have looked in freeswitch's mod folder and it doesn't have mod_curl. I am using a default install of FusionPBX
On Debian 8 with the FreeSWITCH package you would run the following.
apt install freeswitch-mod-curl
Then go to the Menu -> Advanced -> Modules and make sure the module is setup to run automatically and make sure its started.
Then follow instructions found here.
https://wiki.freeswitch.org/wiki/Mod_curl
There actually is mod_curl, though not compiled by default. You may need to follow the steps to compile it yourself.
You have the option to use it directly in dialplan, or in lua script.

go tool: no such tool "tour"

I'm trying out Go for the first time. I was following these docs and wanted to run the go tour locally, but I haven't figured out how to get it to work.
Where is the tool "tour" supposed to be found?
I'm on OSX 10.11.3, and I installed Go via Homebrew
my Go entries in .zshrc
export GOPATH=$HOME/code/Go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
tour is not installed by default with an installation of go. You need to go get it:
go get golang.org/x/tour/gotour
Docs: https://github.com/golang/tour/
I had a problem too. This's my solution, on OSX let try
gotour
With version go1.8.1 darwin/amd64
It works for me using go1.4, but not with go1.7. If you just run go tool, it gives you a list of known tools. They seem to have removed it from tools.
$ gvm use go1.7
$ go tool
addr2line
api
asm
cgo
compile
cover
dist
doc
fix
link
nm
objdump
pack
pprof
trace
vet
yacc
$ gym use go1.4
$ go tool
6a
6c
6g
6l
addr2line
cgo
cover
dist
fix
nm
objdump
pack
pprof
tour # <--- here
vet
yacc
Firstly, it is no longer gotour. And secondly, for the time being, the tour package is located at: golang.org/x/website/tour as opposed to what A Tour of Go Welcome Page says.
So, at least for now:
The correct way to get tour is:
go get golang.org/x/website/tour
Or,
go install golang.org/x/website/tour#latest
After which you can run the command in the terminal:
$ tour
2021/06/22 17:46:48 Serving content from /home/user/go/pkg/mod/golang.org/x/website/tour#v0.0.0-20210616181959-e0d934b43647
2021/06/22 17:46:48 A browser window should open. If not, please visit http://127.0.0.1:3999
2021/06/22 17:46:52 accepting connection from: 127.0.0.1:33192
To find out where it has been installed, you can do which tour:
$ which tour
/home/user/go/bin//tour
reference
Because of changes in Go package management and introduction of modules, this has changed since the original question. Thus, for future reference (as this is the first Google result), if you have not configured GOPATH environment variable
go get golang.org/x/tour
$HOME/go/bin/tour
Note that the executable is called "tour" instead of "gotour".
Source (with full explanation of why and details): https://stephencharlesweiss.com/getting-going-with-golang/
I've got:
golang.org/x/tour/gotour has moved to golang.org/x/tour
So, this works for me:
go get golang.org/x/tour
then:
tour
When you install go, tour is not installed by default. You need to do a go get golang.org/x/tour/gotour. This downloads gotour in your workspace.
If you configured your PATH properly, gotour command from anywhere in the terminal will open up your browser, but if PATH is not configured properly, do a
$GOPATH/bin/gotour
This command can be used from anywhere in your command line and it opens tour in your default browser
http://whipperstacker.com/2015/09/27/how-to-run-the-go-tour-locally/
https://github.com/golang/tour/blob/master/README.md
Once gotour is installed, it’s executable like other executables are typically stored in the bin directory of your workspace. Inside the bin directory ./gotour will invoke or start gotour, elsewhere the gotour will need to be preceded by a path to where the executable is located. In other words $GOPATH/bin/gotour will invoke or start gotour when you are not inside the bin directory.

Golang profiler cannot find source code

I've included the net/http/pprof package in my code. I can then comfortably run the pprof profiler (on Debian):
go tool pprof http://localhost:9000/debug/pprof/profile
Commands such as top10 or even generating call graphs work as expected. However, as soon as I try to go into a function, it fails:
(pprof) list MyFunc
No source information for mypkg.MyFunc
My GOPATH is set to my project's directory. Do I need any special flags or environment variables while building my source code or while running pprof?
Found the answer with the help of the golang-nuts people. I needed to specify the binary:
go tool pprof mybinary http://localhost:9000/debug/pprof/profile
This way the source code is found and can be listed with the "list" command.
I had the same problem with "net/http/pprof", albeit on windows.
Using "runtime/pprof" instead, with pprof.StartCPUProfile / StopCPUProfile solved it.

Resources