Made info url more useful (start and uptime)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user