Skip to content

Instantly share code, notes, and snippets.

@hackerzhut
Created December 16, 2022 14:34
Show Gist options
  • Save hackerzhut/3cf3efe2d68df0061105448b1c57de3a to your computer and use it in GitHub Desktop.
Save hackerzhut/3cf3efe2d68df0061105448b1c57de3a to your computer and use it in GitHub Desktop.
find language of the repo - gitlab
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
// Replace "GITLAB_HOSTNAME" with the hostname of your GitLab instance
baseURL, _ := url.Parse("https://GITLAB_HOSTNAME/api/v4")
// Replace "YOUR_PRIVATE_TOKEN" with a personal access token
client := &http.Client{}
req, _ := http.NewRequest("GET", baseURL.String()+"/projects/1", nil)
req.Header.Add("PRIVATE-TOKEN", "YOUR_PRIVATE_TOKEN")
res, _ := client.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
// The "language" field in the project response contains the primary language
// of the repository.
fmt.Printf("Primary language of repository: %s\n", body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment