go build: no Go files in /msfs2020-go-master - go

Im trying to rebuild a golang github repository to apply some minor changes.
The go application Im trying to modify is the following https://github.com/lian/msfs2020-go
Please use the provided github link to inspect the file tree.
I used the master branch and extracted it to /user/Documents/msfs2020-go-master
If I call go build from /user/Documents/msfs2020-go-master the output equals: no Go files in /user/Documents/msfs2020-go-master
I tried deleting the go.mod and recreating it with go mod init github.com/lian/msfs2020-go followed with a go mod tidy
but still no Go files in /user/Documents/msfs2020-go-master
Here the current go.mod
module github.com/lian/msfs2020-go
go 1.16
require github.com/gorilla/websocket v1.4.2
And here the go.sum
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
The master was build with 1.14 and Im using 1.16 golang.
All my test go applications/modules run/build/install fine at a "Hello World" developing level.
What did I do wrong? I gladly accept any input and will provide additional information's if requested.

The command go build builds the package in the current working directory. The command reports an error because there is not a package at the root of the repository.
Fix by building the package containing the command. Any of the following will work from the root of the repository:
go build ./vfrmap
or
cd vrfrmap
go build
or
go build github.com/lian/msfs2020-go/vfrmap
See also the file build-vfrmap.sh.

Related

Go mod tidy find module but it's not getting to go.sum

i have a Revel project and i can't start it because everytime i run go mod tidy, it looks like finding module but it's not putting the found module in go.sum
here's my go env
GOENV = C:\Users\mycomp\AppData\Roaming\go\env
GOMOD = C:\Program Files\Go\src\myproject\go.mod
GOPATH = C:\Users\micha\go
go version
go version go1.18.3 windows/amd64
revel version
Revel executing: displays the Revel Framework and Go version
Revel Framework : Unknown (1.1.0 remote master branch)
Revel Cmd : 1.1.2 (1.1.2 remote master branch)
Revel Modules : Unknown (1.1.0 remote master branch)
go mod tidy
go: finding module for package github.com/PaesslerAG/jsonpath
go: finding module for package github.com/tdewolff/test
go: finding module for package github.com/PaesslerAG/gval
go: found github.com/tdewolff/test in github.com/tdewolff/test v1.0.7
go: found github.com/PaesslerAG/gval in github.com/PaesslerAG/gval v1.2.0
go: found github.com/PaesslerAG/jsonpath in github.com/PaesslerAG/jsonpath v0.1.1
go mod init myproject seem working because it create go.mod but it's just odd because it only creates this line, usually it creates a lot of modules i need
module myproject
go 1.18
then when i type go mod tidy, it creates empty go.sum. What do i miss ?
Cause the problem is too complex to reproduce online, i started to debug and reinstall my Go from scractch, between solving a bug where my program can't run i tried several things that might be useful
after Go 1.15 or 1.17 , my Go project can't run properly, so i put it in C:\Program Files\Go\src\<project_name>
The problem that i have is in GOPATH (usually in C:\Users\<comp_name>\go) don't have src folder, that makes it found downloaded module but can't seem to put it in go.mod inside my project
So in the end i reinstall all my Go and Revel. Here's how to delete all your associated Go to really really delete all your files
Delete Go Folder in C:\Program Files\Go\
Delete go folder in C:\Users\<comp_name>\go
View all hidden files and delete folder go-build in C:\Users\<comp_name>\AppData\Local
View all hidden files and delete folder go if any in C:\Users\micha\AppData\Roaming

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+

Lock a specific version of a third party package in Go

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

Go plugin - "plugin was built with a different version of package"

I have an application that loads plugins on startup (daemon). In a subpackage (daemon/interfaces), I have a few interfaces that plugins for this program should use.
This means that the main program also gets imported by the plugin.
I am using Go modules (for both the main program and the plugin) to fix the versions, and I can see in go.mod that it is using the latest version of the main program for the plugin.
I can build them both fine, but when I load the plugin it gives me an error saying
panic: plugin.Open("plugins/my-plugin"): plugin was built with a different version of package daemon/interfaces
I am using Go 1.12.7 to build both of the packages.
I fixed this by adding a replace statement to my plugin go.mod file
module github.com/user/plugin
go 1.12
require (
github.com/user/daemon v1.1.1
)
replace github.com/user/daemon v1.1.1 => ../local/path/to/daemon/
It also helps when you are building the project from outside of the directory where the source code is in by using the full name of the project (go build github.com/user/project/)
There is a related Github issue on the Golang repository that you can find here
Apparently, the issue is still open. The issue opener presented the workaround, which I was able to use. Please look at the history lines below for details.
git clone https://github.com/zimnx/central.git
git clone https://github.com/zimnx/plugins.git
cd central/
go clean -modcache
git checkout v1.0.0
go install -a
cd ../plugins/
rm go.mod
go mod init github.com/zimnx/plugins
echo '' >> go.mod
echo 'replace github.com/zimnx/central => ../central' >> go.mod
go build -buildmode=plugin -o plugin.so
central plugin.so
Works for me. Mistery still... :) The output has been saved for the most curious.

go mod vendor without update to latest

I’m trying to figure out if it’s possible to run go mod vendor without the go tool updating my go.mod file.
I specifically go get package/subpackage#commit and commit my go.mod with the correct version.
Then I run go mod vendor and it automatically bumps the version of the package that I just specifically set.
I’ve looked at this page to no avail: https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away
I need to use vendor because I run a script that edits some of the vendored deps., I’m looking at the following build flow:
GO111MODULE=on go get package/subpackge#commit
GO111MODULE=on go mod vendor
./Script/patch_vendors.sh --write
GO111MODULE=off go build
My other option is modifying the copied source wherever go mod vendor donwloads it to, but
not sure how to approach that.
Thanks in advance
Per https://tip.golang.org/cmd/go/#hdr-Maintaining_module_requirements:
The go command itself automatically updates the go.mod file to maintain a standard formatting and the accuracy of require statements.
Any go command that finds an unfamiliar import will look up the module containing that import and add the latest version of that module to go.mod automatically. […]
Any go command can determine that a module requirement is missing and must be added […].
The go mod vendor command copies in all of the transitive imports of your packages and their tests, so it will automatically update the go.mod file to ensure that all of the imported packages are present.
So the problem here is likely that the commit you've selected for package/subpackage fails to provide some package that appears in the transitive imports of your program. If that is correct, you should find that go list all, go test all, and go mod tidy all make that same edit to your module's requirements.

Resources