The git-parser
is a package meant for parsing git urls
This package also enables listing all files based on there extension
- GitHub
- GitLab
- Azure
package main
import (
"fmt"
giturl "github.com/kubescape/go-git-url"
)
func main() {
fullURl := "https://github.com/kubescape/go-git-url"
gitURL, err := giturl.NewGitURL(fullURl) // initialize and parse the URL
if err != nil {
// do something
}
fmt.Printf(gitURL.GetHostName()) // github.com
fmt.Printf(gitURL.GetOwnerName()) // kubescape
fmt.Printf(gitURL.GetRepoName()) // go-git-url
}
- GitHub
It is recommended to use a GitHub token. Set the GitHub token in the
GITHUB_TOKEN
env
- GitLab
It is recommended to use a GitLab token. Set the GitLab token in the
GITLAB_TOKEN
env
- Azure
It is recommended to use a Azure token. Set the Azure token in the
AZURE_TOKEN
env
// List all files and directories names
all, err := gitURL.ListAllNames()
// List all files names
files, err := gitURL.ListFilesNames()
// List all directories names
dirs, err := gitURL.ListDirsNames()
// List files names with the listed extensions
extensions := []string{"yaml", "json"}
files, err := gitURL.ListFilesNamesWithExtension(extensions)
Different URL support ->
basicURL, err := giturl.NewGitURL("https://github.com/kubescape/go-git-url")
nestedURL, err := giturl.NewGitURL("https://github.com/kubescape/go-git-url/tree/master/files")
fileApiURL, err := giturl.NewGitURL("https://github.com/kubescape/go-git-url/blob/master/files/file0.json")
fileRawURL, err := giturl.NewGitURL("https://raw.githubusercontent.com/kubescape/go-git-url/master/files/file0.json")
// Download all files
all, err := gitURL.DownloadAllFiles()
// Download all files with the listed extensions
extensions := []string{"yaml", "json"}
files, err := gitURL.DownloadFilesWithExtension(extensions)