Пример #1
0
func main() {
	result, err := github.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}

	month := []*github.Issue{}
	year := []*github.Issue{}
	other := []*github.Issue{}

	now := time.Now()
	monthAgo := now.AddDate(0, -1, 0)
	yearAgo := now.AddDate(-1, 0, 0)

	for _, is := range result.Items {
		if is.CreatedAt.After(monthAgo) {
			month = append(month, is)
		} else if is.CreatedAt.After(yearAgo) {
			year = append(year, is)
		} else {
			other = append(other, is)
		}
	}

	fmt.Printf("%d issues:\n", result.TotalCount)
	fmt.Printf("\n%d issues (less than a month old):\n", len(month))
	printIssues(month)
	fmt.Printf("\n%d issues (less than a year old):\n", len(year))
	printIssues(year)
	fmt.Printf("\n%d issues (more than a year old):\n", len(other))
	printIssues(other)
}
Пример #2
0
//go run ex4.10/ex4.10.go repo:golang/go is:open json decoder
func main() {
	result, err := github.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
	now := time.Now()
	fmt.Printf("%d issues:\n", result.TotalCount)
	fmt.Println("Less than a month old:")
	for _, item := range result.Items {
		if now.Sub(item.CreatedAt).Hours()/24 <= 30 {
			fmt.Printf("#%-5d %9.9s %.55s\n",
				item.Number, item.User.Login, item.Title)
		}
	}

	fmt.Println("Less than a year old:")
	for _, item := range result.Items {
		if now.Sub(item.CreatedAt).Hours()/24 <= 365 {
			fmt.Printf("#%-5d %9.9s %.55s\n",
				item.Number, item.User.Login, item.Title)
		}
	}

	fmt.Println("More than a year old:")
	for _, item := range result.Items {
		if now.Sub(item.CreatedAt).Hours()/24 > 365 {
			fmt.Printf("#%-5d %9.9s %.55s\n",
				item.Number, item.User.Login, item.Title)
		}
	}
}
Пример #3
0
//!+
func main() {
	result, err := github.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
	if err := issueList.Execute(os.Stdout, result); err != nil {
		log.Fatal(err)
	}
}
Пример #4
0
//!+
func main() {
	result, err := github.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%d issues:\n", result.TotalCount)
	for _, item := range result.Items {
		fmt.Printf("#%-5d %9.9s %.55s\n",
			item.Number, item.User.Login, item.Title)
	}
}
Пример #5
0
func noMust() {
	//!+parse
	report, err := template.New("report").
		Funcs(template.FuncMap{"daysAgo": daysAgo}).
		Parse(templ)
	if err != nil {
		log.Fatal(err)
	}
	//!-parse
	result, err := github.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
	if err := report.Execute(os.Stdout, result); err != nil {
		log.Fatal(err)
	}
}
Пример #6
0
func main() {
	var lessthanOneYear []string
	var lessthanOneMonth []string
	var morethanOneYear []string
	now := time.Now()
	result, err := github.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%d issues:\n", result.TotalCount)
	for _, item := range result.Items {
		log := fmt.Sprintf("%v\n#%-5d %9.9s %.55s\n",
			item.CreatedAt.Format("2006-01-02"), item.Number, item.User.Login, item.Title)

		addy := item.CreatedAt.AddDate(1, 0, 0)
		addm := item.CreatedAt.AddDate(0, 1, 0)
		if now.After(addy) {
			morethanOneYear = append(morethanOneYear, log)
		} else if now.Before(addm) {
			lessthanOneMonth = append(lessthanOneMonth, log)
		} else {
			lessthanOneYear = append(lessthanOneYear, log)
		}
	}

	fmt.Println("----------------more than a year ago----------------")
	for _, log := range morethanOneYear {
		fmt.Print(log)
	}
	fmt.Println("\n----------------less than a year----------------")
	for _, log := range lessthanOneYear {
		fmt.Print(log)
	}
	fmt.Println("\n----------------less than a month----------------")
	for _, log := range lessthanOneMonth {
		fmt.Print(log)
	}
}