package main import ( "encoding/json" "log" "os" "net/http" // "github.com/go-git/go-git/v5" // "github.com/go-git/go-git/v5/storage/memory" ) type ForgejoRepository struct { ID int `json:"id"` Name string `json:"name"` FullName string `json:"full_name"` HTMLURL string `json:"html_url"` SSHURL string `json:"ssh_url"` CloneURL string `json:"clone_url"` } var API_URL = "/api/v1" var API_USER_REPOS = "/user/repos" func buildApiUrl(host string, token string, api string) string { return host + API_URL + api + "?token=" + token + "&limit=1000" } func buildApiUrlUserRepos(host string, token string) string { return buildApiUrl(host, token, API_USER_REPOS) } func main() { // Get the environment variables for Forgejo URL and api token FJ_HOST := os.Getenv("FJ_HOST") FJ_API_TOKEN := os.Getenv("FJ_API_TOKEN") if FJ_HOST == "" || FJ_API_TOKEN == "" { log.Fatalln("Please configure the FJ_HOST and FJ_API_TOKEN environment variables to use fj.") return } // Get the master repo list from Forgejo by calling the user/repos endpoint repos_json, err := http.Get(buildApiUrlUserRepos(FJ_HOST, FJ_API_TOKEN)) if err != nil { log.Fatalln(err) return } // Deserialize the json into a slice of Repository structs var repos []ForgejoRepository err = json.NewDecoder(repos_json.Body).Decode(&repos) if err != nil { log.Fatalln(err) return } for _, repo := range repos { log.Println(repo.Name + " " + repo.CloneURL) } }