forked from torbiak/gopl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (74 loc) · 2.3 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// ex4.10 prints a table of GitHub issues matching the search terms, organized
// by the past day, month, and year.
package main
import (
"fmt"
"log"
"os"
"time"
"gopl.io/ch4/github"
)
//!+
func main() {
result, err := github.SearchIssues(os.Args[1:])
if err != nil {
log.Fatal(err)
}
format := "#%-5d %9.9s %.55s\n"
now := time.Now()
pastDay := make([]*github.Issue, 0)
pastMonth := make([]*github.Issue, 0)
pastYear := make([]*github.Issue, 0)
day := now.AddDate(0, 0, -1)
month := now.AddDate(0, -1, 0)
year := now.AddDate(-1, 0, 0)
for _, item := range result.Items {
switch {
case item.CreatedAt.After(day):
pastDay = append(pastDay, item)
case item.CreatedAt.After(month) && item.CreatedAt.Before(day):
pastMonth = append(pastMonth, item)
case item.CreatedAt.After(year) && item.CreatedAt.Before(month):
pastYear = append(pastYear, item)
}
}
if len(pastDay) > 0 {
fmt.Printf("\nPast day:\n")
for _, item := range pastDay {
fmt.Printf(format, item.Number, item.User.Login, item.Title)
}
}
if len(pastMonth) > 0 {
fmt.Printf("\nPast month:\n")
for _, item := range pastMonth {
fmt.Printf(format, item.Number, item.User.Login, item.Title)
}
}
if len(pastYear) > 0 {
fmt.Printf("\nPast year:\n")
for _, item := range pastYear {
fmt.Printf(format, item.Number, item.User.Login, item.Title)
}
}
}
//!-
/*
//!+textoutput
$ go build gopl.io/ch4/issues
$ ./issues repo:golang/go is:open json decoder
13 issues:
#5680 eaigner encoding/json: set key converter on en/decoder
#6050 gopherbot encoding/json: provide tokenizer
#8658 gopherbot encoding/json: use bufio
#8462 kortschak encoding/json: UnmarshalText confuses json.Unmarshal
#5901 rsc encoding/json: allow override type marshaling
#9812 klauspost encoding/json: string tag not symmetric
#7872 extempora encoding/json: Encoder internally buffers full output
#9650 cespare encoding/json: Decoding gives errPhase when unmarshalin
#6716 gopherbot encoding/json: include field name in unmarshal error me
#6901 lukescott encoding/json, encoding/xml: option to treat unknown fi
#6384 joeshaw encoding/json: encode precise floating point integers u
#6647 btracey x/tools/cmd/godoc: display type kind of each named type
#4237 gjemiller encoding/base64: URLEncoding padding is optional
//!-textoutput
*/