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