Debian Codegraph @

example/simple/main.go

raw
1 // Copyright 2017 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 // The simple command demonstrates a simple functionality which
7 // prompts the user for a GitHub username and lists all the public
8 // organization memberships of the specified username.
9 package main
10
11 import (
12 "context"
13 "fmt"
14
15 "github.com/google/go-github/v60/github"
16 )
17
18 // Fetch all the public organizations' membership of a user.
19 func fetchOrganizations(username string) ([]*github.Organization, error) {
20 client := github.NewClient(nil)
21 orgs, _, err := client.Organizations.List(context.Background(), username, nil)
22 return orgs, err
23 }
24
25 func main() {
26 var username string
27 fmt.Print("Enter GitHub username: ")
28 fmt.Scanf("%s", &username)
29
30 organizations, err := fetchOrganizations(username)
31 if err != nil {
32 fmt.Printf("Error: %v\n", err)
33 return
34 }
35
36 for i, organization := range organizations {
37 fmt.Printf("%v. %v\n", i+1, organization.GetLogin())
38 }
39 }