diff options
| author | Shulhan <ms@kilabit.info> | 2025-07-17 02:22:30 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-07-17 02:30:40 +0700 |
| commit | 4d4b26dff03083955871439ee6e0ef9bd07c5a1c (patch) | |
| tree | ab239b115d9e39a2a7d8befd3ee37d101afb0c17 /worker.go | |
| download | lilin-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.go | 34 |
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 +} |
