Compare commits
2 Commits
83f283d668
...
5df6dc2c5a
Author | SHA1 | Date |
---|---|---|
|
5df6dc2c5a | |
|
414b1b84d9 |
|
@ -16,7 +16,7 @@ type Issue struct {
|
||||||
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("localhost:8080", nil))
|
log.Fatal(http.ListenAndServe("0.0.0.0:8989", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func surface(w http.ResponseWriter, r *http.Request) {
|
func surface(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
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