Skip to content

Instantly share code, notes, and snippets.

@YagmurOzden
Created December 7, 2022 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YagmurOzden/5a1ff8fdfcf5a71d525469c51679afc0 to your computer and use it in GitHub Desktop.
Save YagmurOzden/5a1ff8fdfcf5a71d525469c51679afc0 to your computer and use it in GitHub Desktop.
Takes data from github and returns the value as string
// Takes data from github and returns the value as string
func TakeDataFromgithub(URL string, FileName string) billy.File {
log.Printf(" Started to fetch data from Github")
fs := memfs.New()
//Authenticate and clone the repository
repo, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
URL: URL,
})
if err != nil {
log.Printf(" Repo could not find. Error: %v", err.Error())
} else {
log.Printf("Fetched Repository : %v", repo)
}
//Reads the repository as byte
file, err := fs.Open(FileName)
if err != nil {
log.Printf("File could not find. Error: %v", err.Error())
} else {
log.Printf("Fetched Repositories File : %v", file.Name())
}
defer func(file billy.File) {
err := file.Close()
if err != nil {
log.Printf(" Cannot close file. Error: %v", err.Error())
}
}(file)
//turns into a string
return file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment