github.com/google/go-github/v42@v42.0.0/example/simple/main.go (about) 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/v42/github" 16 ) 17 18 // Fetch all the public organizations' membership of a user. 19 // 20 func fetchOrganizations(username string) ([]*github.Organization, error) { 21 client := github.NewClient(nil) 22 orgs, _, err := client.Organizations.List(context.Background(), username, nil) 23 return orgs, err 24 } 25 26 func main() { 27 var username string 28 fmt.Print("Enter GitHub username: ") 29 fmt.Scanf("%s", &username) 30 31 organizations, err := fetchOrganizations(username) 32 if err != nil { 33 fmt.Printf("Error: %v\n", err) 34 return 35 } 36 37 for i, organization := range organizations { 38 fmt.Printf("%v. %v\n", i+1, organization.GetLogin()) 39 } 40 }