aboutsummaryrefslogtreecommitdiff
path: root/hotline/stats.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2021-07-28 18:21:52 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2021-07-28 14:21:52 -0700
commit22c599abc18895f73e96095f35b71cf3357d41b4 (patch)
tree482ef57d386c955692ea43c43e4655b3c3763499 /hotline/stats.go
parent71c56068adca18f76ebee86355f000a3e51d3127 (diff)
Move code to hotline dir
Diffstat (limited to 'hotline/stats.go')
-rw-r--r--hotline/stats.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/hotline/stats.go b/hotline/stats.go
new file mode 100644
index 0000000..dd8ea1d
--- /dev/null
+++ b/hotline/stats.go
@@ -0,0 +1,33 @@
+package hotline
+
+import (
+ "fmt"
+ "time"
+)
+
+type Stats struct {
+ LoginCount int `yaml:"login count"`
+ StartTime time.Time `yaml:"start time"`
+ Uptime time.Duration `yaml:"uptime"`
+}
+
+func (s *Stats) String() string {
+ template := `
+Server Stats:
+ Start Time: %v
+ Uptime: %s
+ Login Count: %v
+`
+ d := time.Since(s.StartTime)
+ d = d.Round(time.Minute)
+ h := d / time.Hour
+ d -= h * time.Hour
+ m := d / time.Minute
+
+ return fmt.Sprintf(
+ template,
+ s.StartTime.Format(time.RFC1123Z),
+ fmt.Sprintf("%02d:%02d", h, m),
+ s.LoginCount,
+ )
+}