program tip

개인 저장소를 "가져 오는"적절한 방법은 무엇입니까?

radiobox 2020. 8. 22. 08:31
반응형

개인 저장소를 "가져 오는"적절한 방법은 무엇입니까?


$ go get많은 Google이 시도한 후 개인 저장소로 작업 하는 방법을 찾고 있습니다.

첫 번째 시도 :

$ go get -v gitlab.com/secmask/awserver-go
Fetching https://gitlab.com/secmask/awserver-go?go-get=1
https fetch failed.
Fetching http://gitlab.com/secmask/awserver-go?go-get=1
Parsing meta tags from http://gitlab.com/secmask/awserver-go?go-get=1 (status code 200)
import "gitlab.com/secmask/awserver-go": parse http://gitlab.com/secmask/awserver-go?go-get=1: no go-import meta tags
package gitlab.com/secmask/awserver-go: unrecognized import path "gitlab.com/secmask/awserver-go

네, 로그인 정보를 제공하는 방법을 몰라 메타 태그가 보이지 않았습니다.

두 번째 시도 :

https://gist.github.com/shurcooL/6927554를 따르십시오 . .gitconfig에 구성을 추가하십시오.

[url "ssh://git@gitlab.com/"]
    insteadOf = https://gitlab.com/
$ go get -v gitlab.com/secmask/awserver-go --> not work
$ go get -v gitlab.com/secmask/awserver-go.git --> work but I got src/gitlab.com/secmask/awserer-go.git

예, 작동하지만 .git내 프로젝트 이름 으로 확장자를 사용하면 원래 이름으로 이름을 바꿀 수 있지만 매번 $ go get그렇게 좋지는 않습니다. 다른 방법이 있습니까?


구성 할 한 가지가 있습니다. 이 예제는 GitHub를 기반으로하지만 프로세스를 변경해서는 안됩니다.

$ git config --global url.git@github.com:.insteadOf https://github.com/
$ cat ~/.gitconfig
[url "git@github.com:"]
    insteadOf = https://github.com/
$ go get github.com/private/repo

올바른 방법은 저장소를 올바른 위치에 수동으로 배치하는 것입니다. 저장소가 있으면를 사용 go get -u하여 패키지를 업데이트하고 go install설치할 수 있습니다. 이름이 지정된 패키지

github.com/secmask/awserver-go

로 전환

$GOPATH/src/github.com/secmask/awserver-go

입력하는 명령은 다음과 같습니다.

cd $GOPATH/src/github.com/secmask
git clone git@github.com:secmask/awserver-go.git

우리 회사의 gitlab 에서 go get개인 저장소를 사용 하는 데 문제가 있습니다. 해결책을 찾는 데 몇 분이 걸렸습니다. 그리고 나는 이것을 찾았습니다.

  1. https://gitlab.mycompany.com/profile/account 에서 비공개 토큰을 받아야합니다.

  2. 개인 토큰으로 헤더를 추가하도록 git을 구성하십시오.

    $ git config --global http.extraheader "PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN
    
  3. 요청을 ssh 에서 http 로 변환하도록 git을 구성하십시오 .

    $ git config --global url."git@gitlab.mycompany.com:".insteadOf "https://gitlab.mycompany.com/"
    
  4. 마지막으로 go get정상적으로 사용할 수 있습니다 .

    $ go get gitlab.com/company/private_repo
    

GitLab issue 5769 처럼 보입니다 .

GitLab에서는 저장소가 항상로 끝나기 때문에 저장소 이름 끝에 .git지정해야 .git작동합니다. 예를 들면 다음과 같습니다.

import "example.org/myuser/mygorepo.git"

과:

$ go get example.org/myuser/mygorepo.git

GitHub가 ".git".

" Go의 저장소 검색에 대한 지원 추가됨 에서 해결되어야 합니다. # 5958 ”, 올바른 메타 태그가있는 경우 .
Go 자체에는 여전히 문제가 있지만 " cmd/go: go get은 HTML5 문서에서 메타 태그를 찾을 수 없습니다 ".


이미 SSH를 사용하여 자식을 가지고있는 경우에, 이 대답 하여 아마르 Bandukwala는 간단한 해결 방법입니다 :


$ go getgit내부적으로 사용합니다 . 다음 하나의 라이너는 SSH를 통해 패키지를 만들고 git결과적으로 $ go get복제합니다.

Github :

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

BitBucket:

$ git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"

I have created a user specific ssh-config, so my user automatically logs in with the correct credentials and key.

First I needed to generate an key-pair

ssh-keygen -t rsa -b 4096 -C "my@email.here"

and saved it to e.g ~/.ssh/id_my_domain. Note that this is also the keypair (private and public) I've connected to my Github account, so mine is stored in~/.ssh/id_github_com.

I have then created (or altered) a file called ~/.ssh/config with an entry:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_github_com

On another server, the "ssh-url" is admin@domain.com:username/private-repo.git and the entry for this server would have been:

Host domain.com
    HostName domain.com
    User admin
    IdentityFile ~/.ssh/id_domain_com

Just to clarify that you need ensure that the User, Host and HostName is set correctly.

Now I can just browse into the go path and then go get <package>, e.g go get main where the file main/main.go includes the package (from last example above) domain.com:username/private-repo.git.


Generate a github oauth token here and export your github token as an environment variable:

export GITHUB_TOKEN=123

Set git config to use the basic auth url:

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

Now you can go get your private repo.

참고URL : https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository

반응형