forked from google/go-github
/
main.go
40 lines (33 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
40
// 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/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())
}
}