2

I want to install the gqrcode project and get from that project the following installation instructions:

go get -u github.com/KangSpace/gqrcode

When performing this, I first got:

...

fatal: could not read Username for 'https://github.com': terminal prompts disabled

...

After performing

git config --global --add url."git@github.com:".insteadOf "https://github.com/"

I get:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
package github.com/KangSpace/gqrcode: exit status 1

In other languages like python I can clone the library first (git clone ....) and afterwards install it.

How can I perform something similar in go?

user733733
  • 183
  • 1
  • 8
  • 1
    You can clone the repo to a folder, and use `replace` in `go.mod` to point to your local copy. See [How to use a module that is outside of "GOPATH" in another module?](https://stackoverflow.com/questions/52328952/how-to-use-a-module-that-is-outside-of-gopath-in-another-module/52330233#52330233) – icza May 13 '22 at 09:44
  • thanks, that was already really helpful. I changed into the directory of the repository and executed `go mod init gqrcode`. Afterwards I executed `go run qrcode.go` in that directory and get another error message: `build command-line-arguments: cannot load github.com/gqrcode/core/cons: git ls-remote -q https://github.com/gqrcode/core in /home/user/go/pkg/mod/cache/vcs/e2ffcd550d6d1ab2e65ad40d2c1d453aef1bce46b839e0ad91b20ba86131449e: exit status 128: fatal: could not read Username for 'https://github.com': terminal prompts disabled Confirm the import path was entered correctly.` – user733733 May 13 '22 at 10:14
  • 1
    Do this (manual `git clone` and `replace`) with all private repos the `go` tool cannot handle. `github.com/KangSpace/gqrcode` is a public repo and `go` can handle it. – icza May 13 '22 at 10:29
  • 1
    You can also setup a key for `git`, so `go` will be able to fetch all required deps, so no need to do this manually. – icza May 13 '22 at 10:30
  • 1
    check the permission for `ls-la ~/.ssh/id_rsa`, if you have the write permission then remove it by running `chmod 600 id_rsa` – Subham Subhasis Patra May 13 '22 at 11:37
  • Thanks. I supplied my public key at github.com. Now other libraries like `github.com/disintegration/imaging` install without problems. But still when I execute `go get -u -v github.com/KangSpace/gqrcode` I get an error: `github.com/KangSpace/gqrcode (download) github.com/gqrcode/core (download) # cd .; git clone -- https://github.com/gqrcode/core /home/user/go/src/github.com/gqrcode/core Cloning into '/home/user/go/src/github.com/gqrcode/core'... ERROR: Repository not found. fatal: Could not read from remote repository.` Is the github maintainer doing something wrong? – user733733 May 13 '22 at 12:38

1 Answers1

2

If it stills uses an HTTPS URL, despite your global git config url."git@github.com:".insteadOf directive, you might need and try using a PAT (personal access token) instead.

As in this example, try

git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

(Assuming you have access to the repository)

Howver, considering https://github.com/gqrcode itself is 404, the github.com/gqrcode/xxx imports declared in github.com/KangSpace/gqrcode might need to be updated first.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250