aboutsummaryrefslogtreecommitdiff
path: root/worker.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-07-17 02:22:30 +0700
committerShulhan <ms@kilabit.info>2025-07-17 02:30:40 +0700
commit4d4b26dff03083955871439ee6e0ef9bd07c5a1c (patch)
treeab239b115d9e39a2a7d8befd3ee37d101afb0c17 /worker.go
downloadlilin-4d4b26dff03083955871439ee6e0ef9bd07c5a1c.tar.xz
lilin: simple service monitoring
lilin is a program to help monitor other services through HTTP, TCP, and UDP connection.
Diffstat (limited to 'worker.go')
-rw-r--r--worker.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/worker.go b/worker.go
new file mode 100644
index 0000000..d8916b4
--- /dev/null
+++ b/worker.go
@@ -0,0 +1,34 @@
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: GPL-3.0-only
+
+package lilin
+
+import (
+ "maps"
+ "slices"
+ "sync"
+)
+
+// worker contains the report of all services.
+type worker struct {
+ // Internal service status with key is service name.
+ services map[string]Service
+ sync.Mutex
+}
+
+func newWorker() (wrk *worker) {
+ return &worker{
+ services: make(map[string]Service),
+ }
+}
+
+// summary return all services status ordered by name.
+func (wrk *worker) summary() (list []Service) {
+ wrk.Lock()
+ var keys = slices.Sorted(maps.Keys(wrk.services))
+ for _, name := range keys {
+ list = append(list, wrk.services[name])
+ }
+ wrk.Unlock()
+ return list
+}