func CreateInstance(name string, config map[string]interface{}) (m modules.ModuleInstance) { var format string if i, ok := config["format"]; ok { format = i.(string) } else { format = `<span color="{{ color .Load1 }}">{{ .Load1 | printf "%2.2f" }}</span> <span color="{{ color .Load5 }}">{{.Load5 | printf "%2.2f"}}</span> <span color="{{ color .Load15 }}">{{.Load15 | printf "%2.2f"}}</span>` } f := LoadInstance{ name: name, format: format, } if template, err := template.New(name).Funcs(template.FuncMap{ "color": color, }).Parse(format); err == nil { f.template = template } else { log.Error("failed to create template: " + err.Error()) } m = modules.ModuleInstance(f) return }
func CreateInstance(name string, config map[string]interface{}) (instance modules.ModuleInstance) { mpdInstance := MPDInstance{name: name} if v, ok := config["host_name"]; ok { mpdInstance.host_name = v.(string) } else { mpdInstance.host_name = "127.0.0.1" } if v, ok := config["port"]; ok { mpdInstance.port = v.(int) } else { mpdInstance.port = 6600 } var format string if v, ok := config["format"]; ok { format = v.(string) } else { format = "[{{.Status}}] {{ .Artist }} - {{ .Song }}" } if tmpl, err := template.New(mpdInstance.name).Parse(format); err == nil { mpdInstance.template = tmpl } else { log.Error("Failed to parse template:" + format) instance = nil return } instance = modules.ModuleInstance(mpdInstance) return }
func CreateInstance(name string, config map[string]interface{}) (m modules.ModuleInstance) { var format string if i, ok := config["format"]; ok { format = i.(string) } else { format = `Memory: {{ printf "%3.2f %%" .UsedPercent }} ({{ convert .Used }} / {{ convert .Total }})` } f := MemoryInstance{ name: name, format: format, } funcMap := template.FuncMap{ "convert": convert, } if template, err := template.New(name).Funcs(funcMap).Parse(format); err == nil { f.template = template } else { log.Error("failed to create template: " + err.Error()) } m = modules.ModuleInstance(f) return }
func CreateInstance(name string, config map[string]interface{}) (m modules.ModuleInstance) { f := TimeInstance{ name: name, config: config, } if i, ok := config["format"]; ok { f.format = i.(string) } else { f.format = "Mon, 02.01.2006 15:04:05 MST" } m = modules.ModuleInstance(f) return }