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 <cat@ophivana.moe>
This commit is contained in:
parent
2c859c1a46
commit
101b997771
@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pidS = strconv.Itoa(os.Getpid())
|
pidS = strconv.Itoa(os.Getpid())
|
||||||
|
hostname string
|
||||||
launchTime = time.Now().Unix()
|
launchTime = time.Now().Unix()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ var substitute = map[string]func(s *applyState) string{
|
|||||||
"pid": func(_ *applyState) string {
|
"pid": func(_ *applyState) string {
|
||||||
return pidS
|
return pidS
|
||||||
},
|
},
|
||||||
|
"hostname": func(_ *applyState) string {
|
||||||
|
return hostname
|
||||||
|
},
|
||||||
"1min": func(s *applyState) string {
|
"1min": func(s *applyState) string {
|
||||||
s.populateLoadavg()
|
s.populateLoadavg()
|
||||||
return s.loadavg[0]
|
return s.loadavg[0]
|
||||||
|
@ -9,6 +9,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if h, err := os.Hostname(); err != nil {
|
||||||
|
log.Fatalf("error reading hostname: %s", err)
|
||||||
|
} else {
|
||||||
|
hostname = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *applyState) populateLoadavg() {
|
func (s *applyState) populateLoadavg() {
|
||||||
if s.loadavg != nil {
|
if s.loadavg != nil {
|
||||||
return
|
return
|
||||||
|
@ -18,7 +18,7 @@ var defaultConfig = config{
|
|||||||
Timestamps: &rpcfetch.ActivityTimestamps{Start: &launchTime},
|
Timestamps: &rpcfetch.ActivityTimestamps{Start: &launchTime},
|
||||||
Assets: &rpcfetch.ActivityAssets{
|
Assets: &rpcfetch.ActivityAssets{
|
||||||
LargeImage: "yorha",
|
LargeImage: "yorha",
|
||||||
LargeText: "1252927154480611351",
|
LargeText: "%hostname",
|
||||||
SmallImage: "flan",
|
SmallImage: "flan",
|
||||||
SmallText: "PID: %pid",
|
SmallText: "PID: %pid",
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user