Created
August 30, 2018 20:25
-
-
Save rms1000watt/24a05f188a10d6f27c1c5b7eaa8571a1 to your computer and use it in GitHub Desktop.
Clone Git Repo in Pure Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"errors" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"strings" | |
"github.com/aws/aws-lambda-go/events" | |
"github.com/aws/aws-lambda-go/lambda" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
"gopkg.in/src-d/go-git.v4" | |
"gopkg.in/src-d/go-git.v4/plumbing/transport/http" | |
) | |
// ... | |
func clone() (dir string, err error) { | |
auth := http.BasicAuth{ | |
Username: gitUser, | |
Password: gitPass, | |
} | |
dir, err = ioutil.TempDir("", "git") | |
if err != nil { | |
fmt.Println("Failed creating tmp dir:", err) | |
return | |
} | |
opts := git.CloneOptions{ | |
URL: gitURL, | |
Auth: &auth, | |
} | |
if _, err = git.PlainClone(dir, false, &opts); err != nil { | |
fmt.Println("Failed cloning repo:", err) | |
return | |
} | |
return | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment