How to Use the GitHub API in Go (go-github)

Web
Use the go-github library to authenticate and call GitHub API endpoints for automating repository management.

Use the github.com/google/go-github/v62/github library to authenticate and call GitHub API endpoints.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/google/go-github/v62/github"
)

func main() {
	ctx := context.Background()
	client := github.NewClient(nil)
	
	user, _, err := client.Users.Get(ctx, "")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(user.GetLogin())
}

Install the library with go get github.com/google/go-github/v62/github and replace nil with oauth2.NewClient(ctx, token) for private repositories.