Categorygithub.com/kubescape/go-git-url
modulepackage
0.0.30
Repository: https://github.com/kubescape/go-git-url.git
Documentation: pkg.go.dev

# README

GIT Parser

The git-parser is a package meant for parsing git urls

This package also enables listing all files based on there extension

Parser

Supported parsers

  • GitHub
  • GitLab
  • Azure

Parse a git URL

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
}

Git API support

Supported APIs

  • 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 files and directories


// 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 files


// Download all files
all, err := gitURL.DownloadAllFiles()

// Download all files with the listed extensions
extensions := []string{"yaml", "json"}
files, err := gitURL.DownloadFilesWithExtension(extensions)

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

NewGitAPI get instance of git api.
NewGitURL get instance of git parser.

# Interfaces

No description provided by the author
IGitURL parse git urls.