From 4529b473dc12d8a4d1b49c9ee1ba89897f86d616 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 05:24:11 -0600 Subject: add LinuxStatus() Signed-off-by: Jeff Carr --- linuxstatus/timer.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 linuxstatus/timer.go (limited to 'linuxstatus/timer.go') diff --git a/linuxstatus/timer.go b/linuxstatus/timer.go new file mode 100644 index 0000000..cd82f49 --- /dev/null +++ b/linuxstatus/timer.go @@ -0,0 +1,31 @@ +package linuxstatus + +import ( + "time" + "sort" + "strings" +) + +// timeFunction takes a function as an argument and returns the execution time. +func timeFunction(f func()) time.Duration { + startTime := time.Now() // Record the start time + f() // Execute the function + return time.Since(startTime) // Calculate the elapsed time +} + +// sortLines takes a string, splits it on newlines, sorts the lines, +// and rejoins them with newlines. +func sortLines(input string) string { + lines := strings.Split(input, "\n") + + // Trim leading and trailing whitespace from each line + for i, line := range lines { + lines[i] = strings.TrimSpace(line) + } + + sort.Strings(lines) + tmp := strings.Join(lines, "\n") + tmp = strings.TrimLeft(tmp, "\n") + tmp = strings.TrimRight(tmp, "\n") + return tmp +} -- cgit v1.2.3