Compare commits
No commits in common. "5df6dc2c5a4e2f9cd829ea4a9ad4bced968bda07" and "83f283d668c269ca7f8aa3bfc58e7dd6be9e790b" have entirely different histories.
5df6dc2c5a
...
83f283d668
|
@ -12,11 +12,11 @@ type IssuesSearchResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
Number int
|
Number int
|
||||||
HTMLURL string `json:"html_url"`
|
HTMLURL string `json:"html_url"`
|
||||||
Title string
|
Title string
|
||||||
State string
|
State string
|
||||||
User *User
|
*User
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
Body string // in Markdown format
|
Body string // in Markdown format
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ var ConcerError error
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
http.HandleFunc("/", surface)
|
http.HandleFunc("/", surface)
|
||||||
log.Fatal(http.ListenAndServe("0.0.0.0:8989", nil))
|
log.Fatal(http.ListenAndServe("localhost:8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func surface(w http.ResponseWriter, r *http.Request) {
|
func surface(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Study/pkg/GithubApi"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Issues = template.Must(template.New("issuelist").
|
|
||||||
Funcs(template.FuncMap{"dayAgo": daysFormat}).
|
|
||||||
Parse(`
|
|
||||||
<h1>{{.TotalCount}} issues</h1>
|
|
||||||
<table>
|
|
||||||
<tr style='text-align: left'>
|
|
||||||
<th>#</th>
|
|
||||||
<th>State</th>
|
|
||||||
<th>Date</th>
|
|
||||||
<th>User</th>
|
|
||||||
<th>Title</th>
|
|
||||||
</tr>
|
|
||||||
{{range .Items}}
|
|
||||||
<tr>
|
|
||||||
<td><a href='{{.HTMLURL}}'>{{.Number}}</a></td>
|
|
||||||
<td>{{.State}}</td>
|
|
||||||
<td>{{.CreatedAt | dayAgo}}</td>
|
|
||||||
<td><a href='{{.User.HTMLURL}}'>{{.User.Login}}</a></td>
|
|
||||||
<td><a href='{{.HTMLURL}}'>{{.Title}}</a></td>
|
|
||||||
</tr>
|
|
||||||
{{end}}
|
|
||||||
</table>
|
|
||||||
`))
|
|
||||||
|
|
||||||
const layout = "2006-01-02 15:04:05"
|
|
||||||
|
|
||||||
func daysAgo(t time.Time) float64 {
|
|
||||||
return time.Since(t).Hours() / 24.0
|
|
||||||
}
|
|
||||||
func daysFormat(t time.Time) string {
|
|
||||||
return t.Format(layout)
|
|
||||||
}
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", serch)
|
|
||||||
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
func serch(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := r.URL.Query()
|
|
||||||
|
|
||||||
s := vars.Get("s")
|
|
||||||
if s == "" {
|
|
||||||
s = "repo:golang/go"
|
|
||||||
}
|
|
||||||
date := vars.Get("date")
|
|
||||||
if date == "" {
|
|
||||||
date = "30"
|
|
||||||
}
|
|
||||||
dateI, _ := strconv.Atoi(date)
|
|
||||||
res, err := GithubApi.SearchIssues([]string{s}, dateI, "")
|
|
||||||
//res, err := github.SearchIssues([]string{"repo:golang/go"})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := Issues.Execute(w, res); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Study/pkg/github"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const temple = `{{.TotalCount}} issues:
|
|
||||||
{{range .Items}}----------------------------------------
|
|
||||||
Number: {{.Number}}
|
|
||||||
User: {{.User.Login}}
|
|
||||||
Title: {{.Title | printf "%.64s"}}
|
|
||||||
Age: {{.CreatedAt | daysAgo}} days
|
|
||||||
{{end}}`
|
|
||||||
|
|
||||||
func dayAgo(t time.Time) float64 {
|
|
||||||
return time.Since(t).Hours() / 24.0
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
report, err := template.New("report").
|
|
||||||
Funcs(template.FuncMap{"daysAgo": dayAgo}).
|
|
||||||
Parse(temple)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := github.SearchIssues([]string{"go/golang"})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
//if err := report.ExecuteTemplate(os.Stdout, "temple", res); err != nil {
|
|
||||||
if err := report.Execute(os.Stdout, res); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"Study/pkg/github"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
var IssueList = template.Must(template.New("issuelist").Parse(`
|
|
||||||
<h1>{{.TotalCount}} issues</h1>
|
|
||||||
<table>
|
|
||||||
<tr style='text-align: left'>
|
|
||||||
<th>#</th>
|
|
||||||
<th>State</th>
|
|
||||||
<th>User</th>
|
|
||||||
<th>Title</th>
|
|
||||||
</tr>
|
|
||||||
{{range .Items}}
|
|
||||||
<tr>
|
|
||||||
<td><a href='{{.HTMLURL}}'>{{.Number}}</a></td>
|
|
||||||
<td>{{.State}}</td>
|
|
||||||
<td><a href='{{.User.HTMLURL}}'>{{.User.Login}}</a></td>
|
|
||||||
<td><a href='{{.HTMLURL}}'>{{.Title}}</a></td>
|
|
||||||
</tr>
|
|
||||||
{{end}}
|
|
||||||
</table>
|
|
||||||
`))
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
res, err := github.SearchIssues([]string{"repo:golang/go", "3133", "10535"})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
//if err := report.ExecuteTemplate(os.Stdout, "temple", res); err != nil {
|
|
||||||
if err := IssueList.Execute(os.Stdout, res); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
const templ = `<p>A:{{.A}}</p> <p>B: {{.B}}</p>`
|
|
||||||
|
|
||||||
var data struct {
|
|
||||||
A string
|
|
||||||
B template.HTML
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", handle)
|
|
||||||
log.Fatal(http.ListenAndServe("0.0.0.0:8989", nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
func handle(w http.ResponseWriter, r *http.Request) {
|
|
||||||
t := template.Must(template.New("escape").Parse(templ))
|
|
||||||
data.A = "<b>Hello!</b>"
|
|
||||||
data.B = "<b>Hello!</b>"
|
|
||||||
if err := t.Execute(w, data); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue