chore(utils): v0.0.0 => v0.0.1

This commit is contained in:
Medzik 2021-08-12 21:00:37 +00:00
parent 2537ef6fa3
commit 35298bacfc
3 changed files with 4 additions and 59 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.16
require (
github.com/BurntSushi/toml v0.4.1
github.com/MedzikUser/go-github-selfupdate v1.3.1
github.com/MedzikUser/go-utils v0.0.0
github.com/MedzikUser/go-utils v0.0.1
github.com/blang/semver/v4 v4.0.0
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.7.3

2
go.sum
View File

@ -39,6 +39,8 @@ github.com/MedzikUser/go-github-selfupdate v1.3.1 h1:PlLrOMEucL8B2LNRUaceAgvu17J
github.com/MedzikUser/go-github-selfupdate v1.3.1/go.mod h1:vq1/KNWXN7R/aKZFD5p2rsIdQ+2FSXnlIts1QHEZCM4=
github.com/MedzikUser/go-utils v0.0.0 h1:69tLs7g0vK7GEt0GXVTq8/eSmsnBLOzmomrGtdTvd+0=
github.com/MedzikUser/go-utils v0.0.0/go.mod h1:fRjF5g45iBpgaSylXWDxM1U++na14eJmmx5DwXz0vAE=
github.com/MedzikUser/go-utils v0.0.1 h1:oG/ep8wFg3FVxgc6u+XwUfNPiikFvkW1piMkKKByFIE=
github.com/MedzikUser/go-utils v0.0.1/go.mod h1:fRjF5g45iBpgaSylXWDxM1U++na14eJmmx5DwXz0vAE=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=

View File

@ -6,8 +6,6 @@ import (
"net/http"
"os"
"runtime"
"strconv"
"time"
"github.com/MedzikUser/go-utils/common"
"github.com/gin-gonic/gin"
@ -59,66 +57,11 @@ func Status(c *gin.Context) {
"node": json{
"cluster": config.Toml.Cluster.ID,
"node": config.Toml.Cluster.Node,
"uptime": uptime(),
"uptime": common.Uptime(config.StartTime),
},
})
}
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)
}