Debian Codegraph @

example/topics/main.go

raw
1 // Copyright 2019 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 the functionality that
7 // prompts the user for a GitHub topic and lists all the entities
8 // that are related to the specified topic or subject.
9 package main
10
11 import (
12 "context"
13 "fmt"
14
15 "github.com/google/go-github/v60/github"
16 )
17
18 // Fetch and lists all the public topics associated with the specified GitHub topic
19 func fetchTopics(topic string) (*github.TopicsSearchResult, error) {
20 client := github.NewClient(nil)
21 topics, _, err := client.Search.Topics(context.Background(), topic, nil)
22 return topics, err
23 }
24
25 func main() {
26 var topic string
27 fmt.Print("Enter GitHub topic: ")
28 fmt.Scanf("%s", &topic)
29
30 topics, err := fetchTopics(topic)
31 if err != nil {
32 fmt.Printf("Error: %v\n", err)
33 return
34 }
35
36 for _, topic := range topics.Topics {
37 fmt.Println(*topic.Name)
38 }
39 }