/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ package main import ( "context" "fmt" "log" "os" "os/signal" "golang.org/x/sys/unix" ) func main() { ctx, cancel := context.WithCancel(context.Background()) // Catch signals go func() { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, unix.SIGINT, unix.SIGTERM) _ = <-sigChan log.Println("caught signal") cancel() }() accessToken, ok := os.LookupEnv("GITLAB_ACCESS_TOKEN") if !ok { log.Fatal("environment variable GITLAB_ACCESS_TOKEN is not set") } client := NewGitLabClient(ctx, accessToken) pager := FetchGitLabProjects(client) for p := range pager.Iter() { fmt.Printf("%s (%s)\n", p.HTTPURLToRepo, p.Visibility) } if err := pager.LastErr(); err != nil { log.Fatal(fmt.Sprintf("fetch gitlab projects: %v", err)) } }