Ejemplo n.º 1
0
func RenderInstance(i modules.ModuleInstance) (t modules.Item) {

	instance := i.(TimeInstance)

	now := time.Now()
	formatted := now.Format(instance.format)
	t = modules.Item(TimeItem{Name: instance.name, Text: formatted})

	return
}
Ejemplo n.º 2
0
func (t IRPGInstance) Render() (i modules.Item) {

	item := IRPGItem{Name: t.name, Markup: "pango"}

	player := t.downloadData()
	if player == nil {
		return
	}

	var formatted bytes.Buffer
	t.template.Execute(&formatted, player)

	item.Text = formatted.String()

	i = modules.Item(item)
	return
}
Ejemplo n.º 3
0
func RenderInstance(i modules.ModuleInstance) (t modules.Item) {

	instance := i.(LoadInstance)
	var formatted bytes.Buffer

	renderContext := GetRenderContext()

	if instance.template == nil {
		log.Error("template is nil")
		return
	}

	if err := instance.template.Execute(&formatted, renderContext); err != nil {
		log.Fatal(err)
	}

	f := formatted.String()
	log.Debug(f)
	t = modules.Item(LoadItem{Name: instance.name, Text: f, Markup: "pango"})

	return
}
Ejemplo n.º 4
0
func (t NetInstance) Render() (i modules.Item) {

	if t.template == nil {
		log.Error("No template available.")
		return
	}
	_, linkLocalv6, _ := go_net.ParseCIDR("fe80::/10")
	_, privatev6, _ := go_net.ParseCIDR("fd00::/8")

	item := NetItem{Name: t.name, Markup: "pango"}

	interface_name := t.interface_name

	formatData := NetFormatData{Name: t.name, Interface_name: interface_name}

	if iface, err := go_net.InterfaceByName(interface_name); err == nil && iface != nil {
		formatData.Interface = iface
		formatData.Up = (iface.Flags & go_net.FlagUp) != 0
		if addrs, err := iface.Addrs(); err == nil && addrs != nil {
			for _, addr := range addrs {
				if ip, _, err := go_net.ParseCIDR(addr.String()); err == nil {
					if (t.ignore_local) && (linkLocalv6.Contains(ip) || privatev6.Contains(ip)) {
						continue
					}
					formatData.Addresses = append(formatData.Addresses, addr.String())
				}
			}
		}
	}

	var formatted bytes.Buffer
	t.template.Execute(&formatted, formatData)
	item.Text = formatted.String()

	i = modules.Item(item)
	return
}