使用 git 作为存储后端
那么 Go 库fluxcd/go-git-providers
就可以派上用场了。
go-git-providers
是一个通用的 Go 客户端,用于与 Git 提供者的 API(例如 GitHub、GitLab、Bitbucket)进行交互。
例子:
package github_test
import (
"context"
"fmt"
"github.com/fluxcd/go-git-providers/github"
"github.com/fluxcd/go-git-providers/gitprovider"
gogithub "github.com/google/go-github/v32/github"
)
func ExampleOrgRepositoriesClient_Get() {
// Create a new client
ctx := context.Background()
c, err := github.NewClient()
checkErr(err)
// Parse the URL into an OrgRepositoryRef
ref, err := gitprovider.ParseOrgRepositoryURL("https://github.com/fluxcd/flux")
checkErr(err)
// Get public information about the flux repository.
repo, err := c.OrgRepositories().Get(ctx, *ref)
checkErr(err)
// Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct
repoInfo := repo.Get()
// Cast the internal object to a *gogithub.Repository to access custom data
internalRepo := repo.APIObject().(*gogithub.Repository)
fmt.Printf("Description: %s. Homepage: %s", *repoInfo.Description, internalRepo.GetHomepage())
// Output: Description: The GitOps Kubernetes operator. Homepage: https://docs.fluxcd.io
}