Equivalent of python "help()" in go? - 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

Related

Cannot see go.sum after initializing backend of project

I am trying to make a simple Chat app using Golang in order to better understand the application. The tutorial I am following asks to initialize go.sum. After running the following commands, I only see go.mod
go install golang.org/x/tools/gopls#latest
go mod init github.com/TutorialEdge/realtime-chat-go-react
How can I try to resolve this issue?
Thank you in advance!
I looked into possible version errors, but I can't really find a fix. I still can only see go.mod
The tutorial you are referring to is a bit dated in content. In current Go, go.sum is managed by the go mod tidy command.

go 1.14 to 1.17 update -> modules not working anymore

After updating Go from 1.14 to 1.17 I'm getting this error:
main.go:10:2: no required module provides package github.com/gin-gonic/gin: \
go.mod file not found in current directory or any parent directory; \
see 'go help modules'
I used to be able to fix that with go get github.com/gin-gonic/gin but now that doesn't help. Did something change?
I can repro this if I have a file like this:
package hello
import _ "github.com/gin-gonic/gin"
and run these commands:
go mod init hello
go build
Fix for me is running this command:
go mod tidy
As of Go 1.16, “Module-aware mode is enabled by default, regardless of whether a go.mod file is present in the current working directory or a parent directory. More precisely, the GO111MODULE environment variable now defaults to on.”
See the Migrating to Go Modules blog post for a quick overview of how to migrate, or Tutorial: Create a Go Module for more detail.
According to documentation we must use go install example.com/cmd#latest instead of go get for go 1.17+

Difficulty installing go buffalo using go mod on windows

I am very new to golang. I am trying to work with the gomod. Trying to explore the go buffalo framework. But finding a bit of difficulty in installing that.
What I have done:
I saw that go get is nomore supported for buffalo and so switched to go modules.
Created a module by go mod init github.com/webbuffalotest
Fetched go get -v github.com/gobuffalo/buffalo (on the same directory where I have go.mod file)
Fetched go get -v github.com/mattn/go-sqlite3 (on the same directory where I have go.mod file)
go install github.com/gobuffalo/buffalo
I was expecting a buffalo.exe inside %GOPATH%/bin so that I can add it to my path but didn't find one.
My question is what's wrong? Is the exe not installed or it's somewhere else because of go mod. Any help will be highly appreciated.
I am using windows 10. I am not willing to install package managers as scoop or choco to install buffalo. Thanks for your patience :)
Edited:
Also tried setting set GO111MODULE=on but of no use.
Solved:
My bad, I should have used go install github.com/gobuffalo/buffalo/buffalo instead of go install github.com/gobuffalo/buffalo
github.com/gobuffalo/buffalo is a library; the corresponding binary is (aptly-named) github.com/gobuffalo/buffalo/buffalo.
The go install command you ran should have warned you about that, but didn't because go install used to also be used to cache compiled libraries (it no longer does that in module mode).
I've filed https://golang.org/issue/46912 to add a diagnostic.

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.

Build documentation for Go 1 on 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.

Resources