How do you install subcommands? - go

I am getting the following error message in Go v. 1.15.8 darwin/amd64
main.go:8:2: cannot find package "github.com/google/subcommands" in any of:
/usr/local/go/src/github.com/google/subcommands (from $GOROOT)
/Users/user1/go/src/github.com/google/subcommands (from $GOPATH)
The code in main.go looks like:
package main
import (
"flag"
"context"
"os"
"github.com/google/subcommands"
)
I know subcommands is located here: https://github.com/google/subcommands
with the git repo here: https://github.com/google/subcommands.git
But how do I install it?
When I do:
go get github.com/google/subcommands
I get the following error message:
# cd .; git clone -- https://github.com/google/subcommands /Users/user1/go/src/github.com/google/subcommands
Cloning into '/Users/user1/go/src/github.com/google/subcommands'...
fatal: unable to access 'https://github.com/google/subcommands/': Could not resolve host: github.com
package github.com/google/subcommands: exit status 128
When I open my web browser and go to: https://github.com/google/subcommands/ I can see the web page with no problems. So why is the "go get" command having trouble with this?
What am I doing wrong?

In addition of git config, you can also check your environment variable for HTTP_PROXY/HTTPS_PROXY
But more importantly, check if adding GOPROXY=https://proxy.golang.org could help (there are other Go module proxies as well)
This could help getting modules from any provider, GitHub or others.

Related

go get returns unrecognized import path

I have a go program which imports a custom module hosted internally
import (
"fmt"
"log"
...
"gitlab.org.myteam.com/teamrepo/project1"
)
When I do go build I get following errors:
main.go:15:2: no required module provides package gitlab.org.myteam.com/teamrepo/project1; to add it:
go get gitlab.org.myteam.com/teamrepo/project1
As directed when I do go get I get following errors:
go: downloading gitlab.org.myteam.com/teamrepo/project1 v1.0.1
go: gitlab.org.myteam.com/teamrepo/project1#v1.0.1: verifying module: gitlab.org.myteam.com/teamrepo/project1#v1.0.1: reading https://sum.golang.org/lookup/gitlab.org.myteam.com/teamrepo/project1#v1.0.1: 404 Not Found
server response: not found: gitlab.org.myteam.com/teamrepo/project1#v1.0.1: unrecognized import path "gitlab.org.myteam.com/teamrepo/project1": https fetch: Get "https://gitlab.org.myteam.com/teamrepo/project1?go-get=1": dial tcp 10.xx.xx.xxx:443: connect: connection refused

I am not sure what I am doing wrong here. git clone on this repository works fine, so it is accessible.
Further, two things that I find confusing in the errors are:

Why go is trying to read the path reading https://sum.golang.org/lookup/gitlab.org.myteam.com/teamrepo/project1#v1.0.1: 404 Not Found

And, how it decided to fetch version v1.0.1 as I haven’t explicitly specified this version anywhere.
go version go1.19.4 darwin/amd64

unable to get hashicorp / vault

I need to use kmac Hashicorp's Vault implementation. However, when I run the code, the following simple import:
import (
"encoding/hex"
"fmt"
"github.com/hashicorp/vault/sdk/helper/kmac"
)
throws this error: no required module provides package github.com/hashicorp/vault/sdk/helper/kmac/kmac; to add it: go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
If I run:
go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
I get:
go get: module github.com/hashicorp/vault/sdk#upgrade found (v0.2.0), but does not contain package github.com/hashicorp/vault/sdk/helper/kmac/kmac
I also tested to download the latest version but I get the same error. Can I get help?

gotext: extract failed: pipeline: golang.org/x/text/message is not imported

I am trying to run the following command from within my template.go file:
//go:generate gotext -srclang=en update -out=catalog.go -lang=en,de_DE,es_MX,fr_CA,pt_BR
I am expected to get a catalog.go generated, but instead, I get the following error:
gotext: extract failed: pipeline: golang.org/x/text/message is not imported
template.go:3: running "gotext": exit status 1
I do have the following import in the template.go after the generate command:
import (
"time"
log "github.com/sirupsen/logrus"
"golang.org/x/text/message"
)
I've tried to move the import before the generate command. I've also tried to run generate ./... from within the root of the project. I've also tried to run gotext by itself, but it's the same error message.
I also found the following thread on github:
https://github.com/golang/go/issues/26312
I've tried what was suggested there, but it didn't seem to have solved the issue either.
I have solved the issue by running rm -rf vendor/golang.org/x/text command from the root of the project. Of course for things to work, I also needed to have gotext installed. This can be done by running go get golang.org/x/text/cmd/gotext.
I believe the issue could be solved if binaries of .../text/message are installed in the GOPATH/bin as well

Vendoring problem from Opencensus Libraries for Golang

I'm having problem while vendoring my go-project. Tried with both glide and go-dep - getting same problem.
$ go get -u go.opencensus.io gives the following error:
package go.opencensus.io/opencensus-go: unrecognized import path "go.opencensus.io/opencensus-go" (https fetch: Get https://go.opencensus.io/opencensus-go?go-get=1: dial tcp <some-ip>: i/o timeout)
Github link of this package - https://github.com/census-instrumentation/opencensus-go
Tried setting a proxy to shell
export http_proxy=http://104.248.231.49:8080/
export https_proxy=http://104.248.231.49:8080/
And then it worked.

get labix.org/v2/mgo error The remote server unexpectedly closed the connection

I'm trying to run a main.go file Here , and it shows error
cannot find package "labix.org/v2/mgo" in any of:
C:\Go\src\labix.org\v2\mgo (from $GOROOT)
D:\MyFolder\go-in-5-minutes\episode5\src\labix.org\v2\mgo (from $GOPATH)
cannot find package "labix.org/v2/mgo/bson" in any of:
C:\Go\src\labix.org\v2\mgo\bson (from $GOROOT)
D:\MyFolder\go-in-5-minutes\episode5\src\labix.org\v2\mgo\bson (from $GOPATH)
exit status 1 Process exiting with code: 1
so I try to execute
D:\MyFolder\go-in-5-minutes\episode5\> go get labix.org/v2/mgo
But then I got this error:
cd .; bzr branch https://launchpad.net/mgo/v2 D:\MyFolder\go-i
n-5-minutes\episode5\src\labix.org\v2\mgo
bzr: ERROR: The remote server unexpectedly closed the connection.
package labix.org/v2/mgo: exit status 3
How to solve this problem and get labix.org/v2/mgo ?
Currently I replace all the files using
import (
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
)
with
import{
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
}
and pass build and works!

Resources