No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

info.go 630B

1234567891011121314151617181920212223242526272829303132
  1. package server
  2. import (
  3. "encoding/json"
  4. "log"
  5. "net/http"
  6. "time"
  7. )
  8. const Version = "0.0.0"
  9. var start time.Time
  10. func init() {
  11. start = time.Now()
  12. }
  13. // Info provides server version and uptime stats
  14. func (c *Controller) Info(w http.ResponseWriter, req *http.Request) {
  15. log.Println("version requested")
  16. output := struct {
  17. Version string `json:"version"`
  18. Start string `json:"start"`
  19. Uptime string `json:"uptime"`
  20. }{
  21. Version: Version,
  22. Start: start.Format("2006-01-02 15:04:05"),
  23. Uptime: time.Since(start).String(),
  24. }
  25. w.Header().Set("Content-Type", "application/json")
  26. json.NewEncoder(w).Encode(output)
  27. }