From 101b99777169674b17679b30c7097e3b8acb43f6 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Fri, 21 Jun 2024 12:09:50 +0900 Subject: [PATCH] rpcfetch: placeholder: add %hostname placeholder The variable should be assigned a value in the init function of platform-specific apply implementations. Signed-off-by: Ophestra Umiker --- fetch/apply.go | 4 ++++ fetch/apply_linux.go | 8 ++++++++ fetch/config.go | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fetch/apply.go b/fetch/apply.go index b6aa689..41cf497 100644 --- a/fetch/apply.go +++ b/fetch/apply.go @@ -16,6 +16,7 @@ import ( var ( pidS = strconv.Itoa(os.Getpid()) + hostname string launchTime = time.Now().Unix() ) @@ -23,6 +24,9 @@ var substitute = map[string]func(s *applyState) string{ "pid": func(_ *applyState) string { return pidS }, + "hostname": func(_ *applyState) string { + return hostname + }, "1min": func(s *applyState) string { s.populateLoadavg() return s.loadavg[0] diff --git a/fetch/apply_linux.go b/fetch/apply_linux.go index c1c3d29..d24321a 100644 --- a/fetch/apply_linux.go +++ b/fetch/apply_linux.go @@ -9,6 +9,14 @@ import ( "strings" ) +func init() { + if h, err := os.Hostname(); err != nil { + log.Fatalf("error reading hostname: %s", err) + } else { + hostname = h + } +} + func (s *applyState) populateLoadavg() { if s.loadavg != nil { return diff --git a/fetch/config.go b/fetch/config.go index d3237ed..21c7cd0 100644 --- a/fetch/config.go +++ b/fetch/config.go @@ -18,7 +18,7 @@ var defaultConfig = config{ Timestamps: &rpcfetch.ActivityTimestamps{Start: &launchTime}, Assets: &rpcfetch.ActivityAssets{ LargeImage: "yorha", - LargeText: "1252927154480611351", + LargeText: "%hostname", SmallImage: "flan", SmallText: "PID: %pid", },