| OLD | NEW |
| 1 /* | 1 /* |
| 2 Reports version information. | 2 Reports version information. |
| 3 | 3 |
| 4 Requires running "make skiaversion" to set the constants. | 4 Requires running "make skiaversion" to set the constants. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 package skiaversion | 7 package skiaversion |
| 8 | 8 |
| 9 import ( | 9 import ( |
| 10 "encoding/json" | 10 "encoding/json" |
| 11 "net/http" | 11 "net/http" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "github.com/golang/glog" | 14 "github.com/golang/glog" |
| 15 ) | 15 ) |
| 16 | 16 |
| 17 // Date format as reported by 'date --rfc-3339="second"' | 17 // Date format as reported by 'date --rfc-3339="second"' |
| 18 const DATE_FORMAT = "2006-01-02 15:04:05-07:00" | 18 const DATE_FORMAT = "2006-01-02 15:04:05-07:00" |
| 19 | 19 |
| 20 var parsedDate time.Time | 20 var parsedDate time.Time |
| 21 | 21 |
| 22 func init() { | 22 func init() { |
| 23 var err error | 23 var err error |
| 24 parsedDate, err = time.Parse(DATE_FORMAT, DATE) | 24 parsedDate, err = time.Parse(DATE_FORMAT, DATE) |
| 25 if err != nil { | 25 if err != nil { |
| 26 » » glog.Fatal("Failed to parse build date. Did you forget to run \"
make skiaversion\"? %v", err) | 26 » » glog.Fatalf("Failed to parse build date. Did you forget to run \
"make skiaversion\"? %v", err) |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Version holds information about the version of code this program is running. | 30 // Version holds information about the version of code this program is running. |
| 31 type Version struct { | 31 type Version struct { |
| 32 Commit string `json:"commit"` | 32 Commit string `json:"commit"` |
| 33 Date time.Time `json:"date"` | 33 Date time.Time `json:"date"` |
| 34 } | 34 } |
| 35 | 35 |
| 36 // GetVersion returns a Version object for this program. | 36 // GetVersion returns a Version object for this program. |
| 37 func GetVersion() *Version { | 37 func GetVersion() *Version { |
| 38 return &Version{COMMIT, parsedDate} | 38 return &Version{COMMIT, parsedDate} |
| 39 } | 39 } |
| 40 | 40 |
| 41 // JsonHandler is a pre-built handler for HTTP requests which returns version | 41 // JsonHandler is a pre-built handler for HTTP requests which returns version |
| 42 // information in JSON format. | 42 // information in JSON format. |
| 43 func JsonHandler(w http.ResponseWriter, r *http.Request) { | 43 func JsonHandler(w http.ResponseWriter, r *http.Request) { |
| 44 w.Header().Set("Content-Type", "application/json") | 44 w.Header().Set("Content-Type", "application/json") |
| 45 bytes, err := json.Marshal(GetVersion()) | 45 bytes, err := json.Marshal(GetVersion()) |
| 46 if err != nil { | 46 if err != nil { |
| 47 glog.Error(err) | 47 glog.Error(err) |
| 48 } | 48 } |
| 49 w.Write(bytes) | 49 w.Write(bytes) |
| 50 } | 50 } |
| OLD | NEW |