| OLD | NEW |
| 1 package main | 1 package main |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "bytes" | 4 "bytes" |
| 5 "crypto/md5" | 5 "crypto/md5" |
| 6 "database/sql" | 6 "database/sql" |
| 7 "encoding/base64" | 7 "encoding/base64" |
| 8 "encoding/binary" | 8 "encoding/binary" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "flag" | 10 "flag" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // like the IP address of the Graphite monitor. | 296 // like the IP address of the Graphite monitor. |
| 297 addr, _ := net.ResolveTCPAddr("tcp", "skia-monitoring-b:2003") | 297 addr, _ := net.ResolveTCPAddr("tcp", "skia-monitoring-b:2003") |
| 298 go metrics.Graphite(metrics.DefaultRegistry, 1*time.Minute, "webtry", ad
dr) | 298 go metrics.Graphite(metrics.DefaultRegistry, 1*time.Minute, "webtry", ad
dr) |
| 299 | 299 |
| 300 writeOutAllSourceImages() | 300 writeOutAllSourceImages() |
| 301 } | 301 } |
| 302 | 302 |
| 303 func writeOutAllSourceImages() { | 303 func writeOutAllSourceImages() { |
| 304 // Pull all the source images from the db and write them out to inout. | 304 // Pull all the source images from the db and write them out to inout. |
| 305 rows, err := db.Query("SELECT id, image, create_ts FROM source_images OR
DER BY create_ts DESC") | 305 rows, err := db.Query("SELECT id, image, create_ts FROM source_images OR
DER BY create_ts DESC") |
| 306 | |
| 307 if err != nil { | 306 if err != nil { |
| 308 glog.Errorf("Failed to open connection to SQL server: %q\n", err
) | 307 glog.Errorf("Failed to open connection to SQL server: %q\n", err
) |
| 309 panic(err) | 308 panic(err) |
| 310 } | 309 } |
| 310 defer rows.Close() |
| 311 for rows.Next() { | 311 for rows.Next() { |
| 312 var id int | 312 var id int |
| 313 var image []byte | 313 var image []byte |
| 314 var create_ts time.Time | 314 var create_ts time.Time |
| 315 if err := rows.Scan(&id, &image, &create_ts); err != nil { | 315 if err := rows.Scan(&id, &image, &create_ts); err != nil { |
| 316 glog.Errorf("failed to fetch from database: %q", err) | 316 glog.Errorf("failed to fetch from database: %q", err) |
| 317 continue | 317 continue |
| 318 } | 318 } |
| 319 filename := fmt.Sprintf("../../../inout/image-%d.png", id) | 319 filename := fmt.Sprintf("../../../inout/image-%d.png", id) |
| 320 if _, err := os.Stat(filename); os.IsExist(err) { | 320 if _, err := os.Stat(filename); os.IsExist(err) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 471 |
| 472 type Sources struct { | 472 type Sources struct { |
| 473 Id int `json:"id"` | 473 Id int `json:"id"` |
| 474 } | 474 } |
| 475 | 475 |
| 476 // sourcesHandler serves up the PNG of a specific try. | 476 // sourcesHandler serves up the PNG of a specific try. |
| 477 func sourcesHandler(w http.ResponseWriter, r *http.Request) { | 477 func sourcesHandler(w http.ResponseWriter, r *http.Request) { |
| 478 glog.Infof("Sources Handler: %q\n", r.URL.Path) | 478 glog.Infof("Sources Handler: %q\n", r.URL.Path) |
| 479 if r.Method == "GET" { | 479 if r.Method == "GET" { |
| 480 rows, err := db.Query("SELECT id, create_ts FROM source_images W
HERE hidden=0 ORDER BY create_ts DESC") | 480 rows, err := db.Query("SELECT id, create_ts FROM source_images W
HERE hidden=0 ORDER BY create_ts DESC") |
| 481 | |
| 482 if err != nil { | 481 if err != nil { |
| 483 http.Error(w, fmt.Sprintf("Failed to query sources: %s."
, err), 500) | 482 http.Error(w, fmt.Sprintf("Failed to query sources: %s."
, err), 500) |
| 484 } | 483 } |
| 484 defer rows.Close() |
| 485 sources := make([]Sources, 0, 0) | 485 sources := make([]Sources, 0, 0) |
| 486 for rows.Next() { | 486 for rows.Next() { |
| 487 var id int | 487 var id int |
| 488 var create_ts time.Time | 488 var create_ts time.Time |
| 489 if err := rows.Scan(&id, &create_ts); err != nil { | 489 if err := rows.Scan(&id, &create_ts); err != nil { |
| 490 glog.Errorf("failed to fetch from database: %q",
err) | 490 glog.Errorf("failed to fetch from database: %q",
err) |
| 491 continue | 491 continue |
| 492 } | 492 } |
| 493 sources = append(sources, Sources{Id: id}) | 493 sources = append(sources, Sources{Id: id}) |
| 494 } | 494 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 570 |
| 571 type Recent struct { | 571 type Recent struct { |
| 572 Tries []Try | 572 Tries []Try |
| 573 Titlebar Titlebar | 573 Titlebar Titlebar |
| 574 } | 574 } |
| 575 | 575 |
| 576 // recentHandler shows the last 20 tries. | 576 // recentHandler shows the last 20 tries. |
| 577 func recentHandler(w http.ResponseWriter, r *http.Request) { | 577 func recentHandler(w http.ResponseWriter, r *http.Request) { |
| 578 glog.Infof("Recent Handler: %q\n", r.URL.Path) | 578 glog.Infof("Recent Handler: %q\n", r.URL.Path) |
| 579 | 579 |
| 580 var err error | |
| 581 rows, err := db.Query("SELECT create_ts, hash FROM webtry ORDER BY creat
e_ts DESC LIMIT 20") | 580 rows, err := db.Query("SELECT create_ts, hash FROM webtry ORDER BY creat
e_ts DESC LIMIT 20") |
| 582 if err != nil { | 581 if err != nil { |
| 583 http.NotFound(w, r) | 582 http.NotFound(w, r) |
| 584 return | 583 return |
| 585 } | 584 } |
| 585 defer rows.Close() |
| 586 recent := []Try{} | 586 recent := []Try{} |
| 587 for rows.Next() { | 587 for rows.Next() { |
| 588 var hash string | 588 var hash string |
| 589 var create_ts time.Time | 589 var create_ts time.Time |
| 590 if err := rows.Scan(&create_ts, &hash); err != nil { | 590 if err := rows.Scan(&create_ts, &hash); err != nil { |
| 591 glog.Errorf("failed to fetch from database: %q", err) | 591 glog.Errorf("failed to fetch from database: %q", err) |
| 592 continue | 592 continue |
| 593 } | 593 } |
| 594 recent = append(recent, Try{Hash: hash, CreateTS: create_ts.Form
at("2006-02-01")}) | 594 recent = append(recent, Try{Hash: hash, CreateTS: create_ts.Form
at("2006-02-01")}) |
| 595 } | 595 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 tries := []Try{} | 647 tries := []Try{} |
| 648 match := workspaceLink.FindStringSubmatch(r.URL.Path) | 648 match := workspaceLink.FindStringSubmatch(r.URL.Path) |
| 649 name := "" | 649 name := "" |
| 650 if len(match) == 2 { | 650 if len(match) == 2 { |
| 651 name = match[1] | 651 name = match[1] |
| 652 rows, err := db.Query("SELECT create_ts, hash, source_im
age_id FROM workspacetry WHERE name=? ORDER BY create_ts", name) | 652 rows, err := db.Query("SELECT create_ts, hash, source_im
age_id FROM workspacetry WHERE name=? ORDER BY create_ts", name) |
| 653 if err != nil { | 653 if err != nil { |
| 654 reportError(w, r, err, "Failed to select.") | 654 reportError(w, r, err, "Failed to select.") |
| 655 return | 655 return |
| 656 } | 656 } |
| 657 defer rows.Close() |
| 657 for rows.Next() { | 658 for rows.Next() { |
| 658 var hash string | 659 var hash string |
| 659 var create_ts time.Time | 660 var create_ts time.Time |
| 660 var source int | 661 var source int |
| 661 if err := rows.Scan(&create_ts, &hash, &source);
err != nil { | 662 if err := rows.Scan(&create_ts, &hash, &source);
err != nil { |
| 662 glog.Errorf("failed to fetch from databa
se: %q", err) | 663 glog.Errorf("failed to fetch from databa
se: %q", err) |
| 663 continue | 664 continue |
| 664 } | 665 } |
| 665 tries = append(tries, Try{Hash: hash, Source: so
urce, CreateTS: create_ts.Format("2006-02-01")}) | 666 tries = append(tries, Try{Hash: hash, Source: so
urce, CreateTS: create_ts.Format("2006-02-01")}) |
| 666 } | 667 } |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) | 904 http.HandleFunc("/sources/", autogzip.HandleFunc(sourcesHandler)) |
| 904 | 905 |
| 905 // Resources are served directly | 906 // Resources are served directly |
| 906 // TODO add support for caching/etags/gzip | 907 // TODO add support for caching/etags/gzip |
| 907 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) | 908 http.Handle("/res/", autogzip.Handle(http.FileServer(http.Dir("./")))) |
| 908 | 909 |
| 909 // TODO Break out /c/ as it's own handler. | 910 // TODO Break out /c/ as it's own handler. |
| 910 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) | 911 http.HandleFunc("/", autogzip.HandleFunc(mainHandler)) |
| 911 glog.Fatal(http.ListenAndServe(*port, nil)) | 912 glog.Fatal(http.ListenAndServe(*port, nil)) |
| 912 } | 913 } |
| OLD | NEW |