Generation

generate functionWed, 22 Feb 2023

Concurrently make Google search requests for apple,pear,mango and return first results combined in one string separated by new line

package main import ( "context" "fmt" "log" "time" "github.com/google/go-github/github" "golang.org/x/oauth2" ) func main() { client := newGithubClient("") var result []string for _, item := range []string{"apple", "pear", "mango"} { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() repos, _, err := client.Search.Repositories(ctx, item, nil) if err != nil { log.Fatal(err) } result = append(result, *repos.Total) } fmt.Println(result) } func newGithubClient(token string) *github.Client { if token != "" { ts := oauth2.StaticTokenSource(

Questions about programming?Chat with your personal AI assistant