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/json" | 8 "encoding/json" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 name CHAR(64) DEFAULT '' NOT NULL, | 228 name CHAR(64) DEFAULT '' NOT NULL, |
229 create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, | 229 create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, |
230 hash CHAR(64) DEFAULT '' NOT NULL, | 230 hash CHAR(64) DEFAULT '' NOT NULL, |
231 hidden INTEGER DEFAULT 0 NOT NULL, | 231 hidden INTEGER DEFAULT 0 NOT NULL, |
232 | 232 |
233 FOREIGN KEY (name) REFERENCES workspace(name) | 233 FOREIGN KEY (name) REFERENCES workspace(name) |
234 )` | 234 )` |
235 _, err = db.Exec(sql) | 235 _, err = db.Exec(sql) |
236 log.Printf("Info: status creating sqlite table for workspace try
: %q\n", err) | 236 log.Printf("Info: status creating sqlite table for workspace try
: %q\n", err) |
237 } | 237 } |
| 238 |
| 239 // Ping the database to keep the connection fresh. |
| 240 go func() { |
| 241 c := time.Tick(1 * time.Minute) |
| 242 for _ = range c { |
| 243 if err := db.Ping(); err != nil { |
| 244 log.Printf("ERROR: Database failed to respond: %
q\n", err) |
| 245 } |
| 246 } |
| 247 }() |
| 248 |
238 } | 249 } |
239 | 250 |
240 // Titlebar is used in titlebar template expansion. | 251 // Titlebar is used in titlebar template expansion. |
241 type Titlebar struct { | 252 type Titlebar struct { |
242 GitHash string | 253 GitHash string |
243 GitInfo string | 254 GitInfo string |
244 } | 255 } |
245 | 256 |
246 // userCode is used in template expansion. | 257 // userCode is used in template expansion. |
247 type userCode struct { | 258 type userCode struct { |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 http.HandleFunc("/json/", tryInfoHandler) | 688 http.HandleFunc("/json/", tryInfoHandler) |
678 | 689 |
679 // Resources are served directly | 690 // Resources are served directly |
680 // TODO add support for caching/etags/gzip | 691 // TODO add support for caching/etags/gzip |
681 http.Handle("/res/", http.FileServer(http.Dir("./"))) | 692 http.Handle("/res/", http.FileServer(http.Dir("./"))) |
682 | 693 |
683 // TODO Break out /c/ as it's own handler. | 694 // TODO Break out /c/ as it's own handler. |
684 http.HandleFunc("/", mainHandler) | 695 http.HandleFunc("/", mainHandler) |
685 log.Fatal(http.ListenAndServe(*port, nil)) | 696 log.Fatal(http.ListenAndServe(*port, nil)) |
686 } | 697 } |
OLD | NEW |