How to import private repositories on GAE SE Go 1.11, with go modules?

爱⌒轻易说出口 提交于 2021-02-10 13:16:07

问题


I have a go library package repository on github as a private repository.

And I wrote a project like below that import the library package above.

package main

import "github.com/foo/libpackage"

func main() {
  :
}

This is a directory hierarchy.

path/to/project
  |- main.go
  |- go.mod
  `- go.sum

When deploying I got a error that cannot

go: github.com/foo/libpackage@v0.0.0-20181127123728-008fddddc190: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/25a80f32a1edc8de002fe3d4532abdf933bba77505314d051e4b644faa9cabf6: exit status 128:
        fatal: could not read Username for 'https://github.com': terminal prompts disabled

It seems to get failed when go mod download. I think it cause GAE does not be permitted to access a private repository(This is convincing)

Next I tried to run go mod vendor to download repositories into the vendor directory.

path/to/project
  |- vendor/...
  |- main.go
  |- go.mod
  `- go.sum

But I got a same error.

help!


回答1:


Send github credentials to go get:

git config credential.helper '!f() { sleep 1; echo "username=${GIT_USER}\npassword=${GIT_PASSWORD}"; }; f'

export GIT_USER=github_user
export GIT_PASSWORD=github_password_or_token

go get github.com/foo/libpackage


来源:https://stackoverflow.com/questions/53512443/how-to-import-private-repositories-on-gae-se-go-1-11-with-go-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!