Skip to content
Snippets Groups Projects
Commit ef690369 authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

have set up uptime for status

parent f44f9689
Branches
No related tags found
No related merge requests found
......@@ -6,9 +6,13 @@ import (
"log"
"net/http"
"os"
"time"
)
var StartTime = time.Now() // sets StartTime
func main() {
assignment2.StartTime = StartTime // sends StartTime
port := os.Getenv("PORT")
if port == "" {
......
......@@ -7,8 +7,11 @@ import (
"net/http"
"sort"
"strconv"
"time"
)
var StartTime time.Time
func HandlerNil(w http.ResponseWriter, r *http.Request) { //standar default respons
fmt.Println("Default Handler: Invalid request received.")
http.Error(w, "Invalid request", http.StatusBadRequest)
......@@ -151,6 +154,9 @@ func HandlerStatus(w http.ResponseWriter, r *http.Request) {
S.Database = resp.StatusCode
elapse := time.Since(StartTime)
S.Uptime = elapse.Seconds()
S.Version = "v1"
http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good
......
......@@ -54,7 +54,7 @@ type Label struct {
type Status struct {
Gitlab int `json:"gitlab"`
Database int `json:"database"`
Uptime int `json:"uptime"`
Uptime float64 `json:"uptime"`
Version string `json:"version"`
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment