func PrintAllLabels(srv *gmail.Service, user string) []*gmail.Label {
	log.Printf("Listing all Gmail labels")
	labelsResp, err := srv.Users.Labels.List(user).Do()
	if err != nil {
		log.Fatalf("Unable to retrieve all labels: %v", err)
	}
	log.Printf("%d labels found", len(labelsResp.Labels))
	for _, l := range labelsResp.Labels {
		fmt.Println(FormatAsID(l.Name))
	}
	return labelsResp.Labels
}
PrintAllLabels prints all labels for a given user.
package gmailutils
import (
	"context"
	"encoding/base64"
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"strings"
	"sync"
	"time"
	"unicode"
	"unicode/utf8"
	"github.com/bzz/scholar-alert-digest/gmailutils/token"
	"github.com/cheggaaa/pb/v3"
	"golang.org/x/oauth2"
	"golang.org/x/oauth2/google"
	"google.golang.org/api/gmail/v1"
)
const Instructions = `Please follow https: 
in order to:
 - create a new "Quickstart" API project under your account
 - enable GMail API on it
 - download OAuth 2.0 credentials
`
func NewClient(needWriteAccess bool) *http.Client {
	b, err := ioutil.ReadFile("credentials.json")
	if err != nil {
		log.Fatalf("Unable to read client secret file: %v\n%s", err, Instructions)
	}
	scopes := []string{gmail.GmailReadonlyScope}
	token := "token.json"
	if needWriteAccess {
		scopes = append(scopes, gmail.GmailModifyScope)
		token = "token_rw.json"
	}
	config, err := google.ConfigFromJSON(b, scopes...)
	if err != nil {
		log.Fatalf("Unable to parse client secret file to config: %v", err)
	}
	return getClient(config, token)
}
func getClient(config *oauth2.Config, tokFile string) *http.Client {
	tok, err := token.FromFile(tokFile)
	if err != nil {
		tok = token.FromWeb(config)
		token.Save(tokFile, tok)
	}
	return config.Client(context.Background(), tok)
}
func FetchLabels(ctx context.Context, client *http.Client) (
	*gmail.ListLabelsResponse, error) {  
	srv, err := gmail.New(client)
	if err != nil {
		return nil, err
	}
	labelsResp, err := srv.Users.Labels.List("me").Do()
	if err != nil {
		return nil, err
	}
	return labelsResp, nil
}