Made info url more useful (start and uptime)

This commit is contained in:
sm
2015-08-26 22:25:38 -07:00
parent b5cac7c02a
commit 5cac75b638
2 changed files with 34 additions and 18 deletions
+32
View File
@@ -0,0 +1,32 @@
package server
import (
"encoding/json"
"log"
"net/http"
"time"
)
const Version = "0.0.0"
var start time.Time
func init() {
start = time.Now()
}
// Info provides server version and uptime stats
func (c *Controller) Info(w http.ResponseWriter, req *http.Request) {
log.Println("version requested")
output := struct {
Version string `json:"version"`
Start string `json:"start"`
Uptime string `json:"uptime"`
}{
Version: Version,
Start: start.Format("2006-01-02 15:04:05"),
Uptime: time.Since(start).String(),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(output)
}