-
-
Save roscopecoltran/068002a65daaecd5b9bd053ba084340d 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