...
1 package common
2
3 import (
4 "fmt"
5 "sync"
6 )
7
8 var (
9 infolock sync.Mutex
10 info_providers []*infoProviderEntry
11 )
12
13 type infoProviderEntry struct {
14 name string
15 f func() []*InfoValue
16 }
17
18 type InfoValue struct {
19 Name string
20 Value float64
21 }
22
23 func RegisterInfoProvider(name string, ip func() []*InfoValue) {
24 ipe := &infoProviderEntry{name: name, f: ip}
25 infolock.Lock()
26 info_providers = append(info_providers, ipe)
27 infolock.Unlock()
28 return
29 }
30
31 func GetText() map[string]string {
32 res := make(map[string]string)
33 infolock.Lock()
34 for _, ip := range info_providers {
35 s := ""
36 ivs := ip.f()
37 for _, iv := range ivs {
38 x := fmt.Sprintf("%s:%0.2f\n", iv.Name, iv.Value)
39 s = s + x
40 }
41 res[ip.name] = s
42 }
43 infolock.Unlock()
44 return res
45 }
46
View as plain text