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.
Related
So I installed gorilla/mux to use it for my API by typing this code on terminal
go get -u github.com/gorilla/mux
And since it didn't return any errors (nor any texts) I thought the install was successful. But When I started to use "mux. "something, vscode showed that the name "mux" is not declared. Does anyone had any similar experience or know how to solve the problem? Thanks in advance.
(Using go1.18.3)
Your project doesn't have go.sum file.
Run go mod tidy and you will be good to go.
So,I recently started following a video tutorial and i am fairly new to golang and tried installing the forked version of bolt db using
$ go get go.etcd.io/bbolt/...
Note : I want to use this specific version
but i am getting an error which says
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd#latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'
I read a few GitHub issues which say that go get is deprecated so how do I resolve this ?
I also tried few other things such as
go install go.etcd.io/bbolt/...
Go modules are today's standard. Especially if you are new to Go; do not spend time on material that do not use (and teach) them.
Run go mod init yourproject
in your project repository root directory. This will create go.mod file.
Once you have that you can either:
import go.etcd.io/bbolt in source code and then run go mod tidy. Go tool will find and add module to your dependencies (go.mod file). This is described in Getting started tutorial.
run go get go.etcd.io/bbolt directly, that will update dependencies too.
Using Go Modules series explains workflow in detail and will be helpful when converting commands from an outdated material.
Using modules, when I try to lock down a specific version of a package using the following command:
go mod edit -require "google.golang.org/grpc#v1.10.0"
It shows this under the require section in the go.mod file:
google.golang.org/protobuf v1.10.0
And then when I run:
go mod vendor
It is always pulling down the latest version which is currently v1.24.0. Under the require section in the go.mod file it shows:
google.golang.org/protobuf v1.24.0
Is there a way to lock a specific version no matter what?
I am currently using go version 1.14.3.
Thanks!
It seems that it is possible to tell go mod to only get the versions specified without bumping the version.
go -mod=readonly mod vendor
Can be found at: https://github.com/thepudds/go-module-knobs/blob/master/README.md
One way to fix this problem is do go build once you have made specific changes to go mod file. This will ensure you have go.sum file built into your codebase. This is nothing but checksum of your fetched package. By doing this, all the future pull will match the checksum of go.sum file
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
I have a weird issue with golang. I run the command (like everytime):
go run main.go
Then I made some change into my code and then I run again:
go run main.go
But the executed code is the old version of the code. So I tried some stuff:
Reboot the computer
Delete all the temporary binaries into temp folder
Reinstall go
Delete and put back my code
Remove some file
But it is still running my old version of the code. I didn't find solution about this issue, and the few post about it doesn't give a solution (here and here).
About my configuration it is the following:
Raspberry pi running Raspbian (updated)
Go version 1.8.1
I hope you can help me !
Thank in advance!
Best regards,
Okay!
The problem come from the imports. In the code some imports was calling old version of the code.
I think your GOPATH is pointing to a wrong folder. Please, run go env to make sure that it is pointing to the right directory. If not set it to location where go files are. Please, take into account that go run usually does not need a file specification and if you do you have to list defacto all files of your app that main.go depends upon.
Have a look ``here