diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 65c22ab..bfc6a5a 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -3,7 +3,4 @@ FROM gitpod/workspace-full # GoReleaser RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -# GoLangCI Lint -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1 - RUN npm i -g nodemon diff --git a/.goreleaser.yml b/.goreleaser.yml index b7bce03..3e8a5a7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,6 +15,7 @@ builds: ldflags: - -s -w - -X gitlab.com/gaming0skar123/go/pingbot/config.Version={{.RawVersion}} + - -X gitlab.com/gaming0skar123/go/pingbot/config.Build={{.Date}} archives: - format: tar.gz diff --git a/config.schema.toml b/config.schema.toml index ee8239b..a19ef69 100644 --- a/config.schema.toml +++ b/config.schema.toml @@ -13,3 +13,7 @@ check=2 # Check every two minutes [cluster] id=1 # Cluster ID node=1 # Node ID + +[mongodb] +database="PingBot" +collection="URL" diff --git a/config/constant.go b/config/constant.go index fdeb016..4eadead 100644 --- a/config/constant.go +++ b/config/constant.go @@ -1,4 +1,11 @@ package config +import "time" + const GH_Repo = "MedzikUser/go-pingbot" -var Version = "dev" + +var ( + Version = "dev" + Build = "" + StartTime time.Time +) diff --git a/config/env.go b/config/env.go index 6f2452a..31c2ee8 100644 --- a/config/env.go +++ b/config/env.go @@ -6,7 +6,9 @@ import ( _ "github.com/joho/godotenv/autoload" ) -// mongo -var Mongo_URI = os.Getenv("MONGODB_URI") -var Mongo_DB = os.Getenv("MONGODB_DB") -var Mongo_Collection = os.Getenv("MONGODB_COLLECTION") +var ( + // mongo + Mongo_URI = os.Getenv("MONGODB_URI") + Mongo_DB = os.Getenv("MONGODB_DB") + Mongo_Collection = os.Getenv("MONGODB_COLLECTION") +) diff --git a/database/mongo/type.go b/database/mongo/types.go similarity index 100% rename from database/mongo/type.go rename to database/mongo/types.go diff --git a/main.go b/main.go index a3b0650..2fc77bb 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "sync" + "time" "gitlab.com/gaming0skar123/go/pingbot/backend" "gitlab.com/gaming0skar123/go/pingbot/common" @@ -41,5 +42,7 @@ func main() { log.Warn("Auto Update -> Disabled") } + config.StartTime = time.Now() + wg.Wait() } diff --git a/website/routes/api/status.go b/website/routes/api/status.go index 0ba2adf..60ffc41 100644 --- a/website/routes/api/status.go +++ b/website/routes/api/status.go @@ -6,6 +6,8 @@ import ( "net/http" "os" "runtime" + "strconv" + "time" "github.com/gin-gonic/gin" "github.com/struCoder/pidusage" @@ -52,14 +54,72 @@ func Status(c *gin.Context) { "v": json{ "go": runtime.Version(), "release": config.Version, + "build": config.Build, }, "node": json{ "cluster": config.Toml.Cluster.ID, "node": config.Toml.Cluster.Node, + //"uptime": time.Since(config.StartTime).String(), + "uptime": uptime(), }, }) } +func uptime() string { + t := time.Since(config.StartTime) + + var uptime string + + var ( + y int + d int + ) + + h := round(t.Hours()) + m := round(t.Minutes()) + s := round(t.Seconds()) + + for h/24 > 0 { + d++ + h -= 24 + } + + for d/365 > 0 { + y++ + d -= 365 + } + + if y > 0 { + uptime += strconv.Itoa(y) + "y " + } + + if d > 0 { + uptime += strconv.Itoa(d) + "d " + } + + if h > 0 { + uptime += strconv.Itoa(h) + "h " + } + + if m > 0 { + uptime += strconv.Itoa(m-(round(t.Hours())*60)) + "m " + } + + if s > 0 { + uptime += strconv.Itoa(s-(m*60)) + "s" + } + + return uptime +} + +func round(val float64) int { + if val < 0 { + return int(val - 1.0) + } + + return int(val) +} + func mb(b uint64) string { return fmt.Sprintf("%d MB", b/1000/1000) } diff --git a/website/routes/api/type.go b/website/routes/api/types.go similarity index 100% rename from website/routes/api/type.go rename to website/routes/api/types.go