From 6988a0571d5d37ea0f38ee3e4066533158f608bc Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sat, 24 Jul 2021 17:54:17 -0700 Subject: Initial squashed commit --- stats.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 stats.go (limited to 'stats.go') diff --git a/stats.go b/stats.go new file mode 100644 index 0000000..dd8ea1d --- /dev/null +++ b/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, + ) +} -- cgit