Unable to compile simple go program using foundationdb - go

Trying to cross compile on macos arm for linux. My sample project looks like this:
main.go:
package main
import(
"github.com/apple/foundationdb/bindings/go/src/fdb"
)
func main() {
fdb.APIVersion(630)
fdb.MustOpenDatabase("fdb.cluster")
}
go.mod
module fdbtest
go 1.19
require github.com/apple/foundationdb/bindings/go v0.0.0-20221026173525-97cc643cef69
require golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
go.sum
github.com/apple/foundationdb/bindings/go v0.0.0-20221026173525-97cc643cef69 h1:vG55CLKOUgyuD15KWMxqRgTPNs8qQfXPtWjYYN5Wai0=
github.com/apple/foundationdb/bindings/go v0.0.0-20221026173525-97cc643cef69/go.mod h1:w63jdZTFCtvdjsUj5yrdKgjxaAD5uXQX6hJ7EaiLFRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
I've installed foundationdb go lang bindings via go get github.com/apple/foundationdb/bindings/go#6.3.25
but when I do env GOOS=linux GOARCH=amd64 go build I get the following errors:
env GOOS=linux GOARCH=amd64 go build
# github.com/apple/foundationdb/bindings/go/src/fdb
../../../go/pkg/mod/github.com/apple/foundationdb/bindings/go#v0.0.0-20221026173525-97cc643cef69/src/fdb/keyselector.go:39:10: undefined: KeyConvertible
../../../go/pkg/mod/github.com/apple/foundationdb/bindings/go#v0.0.0-20221026173525-97cc643cef69/src/fdb/snapshot.go:33:3: undefined: transaction
../../../go/pkg/mod/github.com/apple/foundationdb/bindings/go#v0.0.0-20221026173525-97cc643cef69/src/fdb/generated.go:45:9: undefined: NetworkOptions
<...>
../../../go/pkg/mod/github.com/apple/foundationdb/bindings/go#v0.0.0-20221026173525-97cc643cef69/src/fdb/generated.go:94:9: too many errors
So it seems that it cannot find any of the types from fdb. Yet the KeyConvertible and the NetworkOptions (and others) exist in ../../../go/pkg/mod/github.com/apple/foundationdb/bindings/go#v0.0.0-20221026173525-97cc643cef69/src/fdb/fdb.go
My golang version: go version go1.19.3 darwin/arm64
Newer fdb go bindings (7.1.25, 7.1.0) seem to behave the same...
what am I missing here?

Related

Go installs latest version of dependency even if specific version is mentioned in go.mod

I am installing golint package in my CI pipeline and I am using Go v1.16. Now because of golint, it installs sys v0.2.0 even if golint's go.mod file has specific versioned dependencies.
golint installs golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 (https://github.com/golang/lint/blob/master/go.mod)
gotools installs golang.org/x/net v0.0.0-20190620200207-3b0461eec859 (https://github.com/golang/tools/blob/2f3ba24bd6e75104fb11be4edf062de340ffd1ab/go.mod)
x/net installs golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a (https://github.com/golang/net/blob/3b0461eec859c4b73bb64fdc8285971fd33e3938/go.mod)
Which is not v0.2.0. But still sys having v0.2.0 is being installed and because of that other code/stages fails with error:
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/syscall.go:83:16: undefined: unsafe.Slice
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
I have also checked release dates for sys here: https://github.com/golang/sys/tags and the above mentioned sys version is from past (from 2019) and it should work with Go v1.16.
What am I missing here?

Deploying Go app on Google Cloud 'missing go.sum entry'

I'm trying to deploy a simple API on Google Cloud using Go 1.19
> go version
go version go1.19.2 windows/amd64
I'm following this documentation as a template to deploy my app. But the deploy fails.
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build xxx status: FAILURE
go: github.com/go-redis/redis/v9#v9.0.0-rc.1 requires
github.com/onsi/ginkgo#v1.16.5: missing go.sum entry; to add it:
go mod download github.com/onsi/ginkgo
Cloud build log:
Running "go build -o /layers/google.go.build/bin/main . (GOCACHE=/layers/google.go.build/gocache)"
go: github.com/go-redis/redis/v9#v9.0.0-rc.1 requires
github.com/onsi/ginkgo#v1.16.5: missing go.sum entry; to add it:
go mod download github.com/onsi/ginkgo
Done "go build -o /layers/google.go.build/bin/main . (GOCACHE=/lay..." (7.516802ms)
Failure: (ID: 721b15b4) go: github.com/go-redis/redis/v9#v9.0.0-rc.1 requires
github.com/onsi/ginkgo#v1.16.5: missing go.sum entry; to add it:
go mod download github.com/onsi/ginkgo
--------------------------------------------------------------------------------
Running "mv -f /builder/outputs/output-5577006791947779410 /builder/outputs/output"
Done "mv -f /builder/outputs/output-5577006791947779410 /builder/o..." (3.938721ms)
ERROR: failed to build: exit status 1
Running the suggested go mod download github.com/onsi/ginkgo does not solve anything.
Also tried go mod tidy as suggested in another posts but same results. Also tried with vendor folder, but nothing again.
This is my app.yaml
runtime: go116
go.mod
module notams/anac
go 1.19
require (
github.com/go-redis/redis/v9 v9.0.0-rc.1
github.com/gorilla/mux v1.8.0
github.com/joho/godotenv v1.4.0
golang.org/x/exp v0.0.0-20221019170559-20944726eadf
)
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)
go.sum
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs=
github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf h1:nFVjjKDgNY37+ZSYCJmtYf7tOlfQswHqplG2eosjOMg=
golang.org/x/exp v0.0.0-20221019170559-20944726eadf/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
EDIT 1: Already tried to change runtime: go and to runtime: go119 but those are not supported and return "invalid go runtime".
To anyone who might have this problem, I just deployed the app on Cloud Run instead of App Engine and everything runs smoothly. I was not able to deploy it on App Engine and i think that the only way to do so is adapting the code and modules to the latest runtime version available for GCP (currently Go 1.16).

Installing a Go tool from github and facing installation errors

I want to install this tool from github : https://github.com/ethicalhackingplayground/ssrf-tool
I am using the cmd : go install github.com/ethicalhackingplayground/ssrf-tool#latest
Output :
go: finding module for package github.com/projectdiscovery/gologger
go: finding module for package github.com/briandowns/spinner
go: finding module for package github.com/logrusorgru/aurora
go: found github.com/briandowns/spinner in github.com/briandowns/spinner v1.18.1
go: found github.com/logrusorgru/aurora in github.com/logrusorgru/aurora v2.0.3+incompatible
go: found github.com/projectdiscovery/gologger in github.com/projectdiscovery/gologger v1.1.4
# github.com/ethicalhackingplayground/ssrf-tool
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:34:2: undefined: gologger.Printf
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:35:2: undefined: gologger.Infof
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:36:2: undefined: gologger.Infof
I am super new to golang, go installation is fine in my system because other tools from github are working fine.
If some changes are required in the code of this tool, please suggest so.
This sources created without go module support and an old version of gologger, here is a workaround:
Clone repository git clone git#github.com:ethicalhackingplayground/ssrf-tool.git
cd ssrf-tool create go.mod file with content:
module github.com/ethicalhackingplayground/ssrf-tool
go 1.17
require (
github.com/briandowns/spinner v1.18.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/projectdiscovery/gologger v1.0.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect
)
download deps go mod download
Build executable go build .
./ssrf-tool --help
Profit.
Here is the repo with the problem fixed.
go install github.com/R0X4R/ssrf-tool#latest
or
git clone https://github.com/R0X4R/ssrf-tool.git
cd ssrf-tool
go build ssrftool.go && mv ssrftool /usr/bin/

could not import google.golang.org/grpc (cannot find package "google.golang.org/grpc"

Hi I installed golang grpc in my vscode project with some go get commands,
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
from https://stackoverflow.com/a/62872353/4159198
my project builds/runs inside vscode and on the command line but autocomplete gives me an error,
could not import google.golang.org/grpc (cannot find package "google.golang.org/grpc" in any of
/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
/home/john/go/src/google.golang.org/grpc (from $GOPATH))
Find from my home directory:
find * -iname google.golang.org
go/src/google.golang.org
go/pkg/mod/google.golang.org
go/pkg/mod/cache/download/google.golang.org
go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/google.golang.org
My .profile bottom,
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:~/go
export GOPATH=/home/john/go
export PATH=$PATH:$GOPATH/bin
I tried copying the source from pkg to src directory.
Try to launch go mod init on every program you want to compile.
If there was packages to imported and it missing, there will be a lightbulb icon that you can click on to automatically go get the packages you want
On your go.mod will there written
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.25.0 // indirect

"go.etcd.io/etcd/clientv3/balancer/picker" - undefined: balancer.PickOptions

I'm getting the following error in golang
# go.etcd.io/etcd/clientv3/balancer/picker
/home/user/go/src/go.etcd.io/etcd/clientv3/balancer/picker/err.go:37:44: undefined: balancer.PickOptions
/home/user/go/src/go.etcd.io/etcd/clientv3/balancer/picker/roundrobin_balanced.go:55:54:
undefined: balancer.PickOptions
# go.etcd.io/etcd/clientv3/balancer/resolver/endpoint
/home/user/go/src/go.etcd.io/etcd/clientv3/balancer/resolver/endpoint/endpoint.go:114:78:
undefined: resolver.BuildOption
/home/user/go/src/go.etcd.io/etcd/clientv3/balancer/resolver/endpoint/endpoint.go:183:31:
undefined: resolver.ResolveNowOption
I have tried
go get -u google.golang.org/grpc
but still getting same issue. My version of grpc is v1.26.0
Any solutions?
Are you sure your version is v1.26.0?
Can you share your go.mod please?
go get -u google.golang.org/grpc
The above command is to retrieve latest version of grpc which is v1.27.1
Once you change the version in your go.mod from
google.golang.org/grpc v1.27.0
to
google.golang.org/grpc v1.26.0
you will need to run following command to lock the version:
go get google.golang.org/grpc#v1.26.0

Resources