Пример #1
0
func (fm *Flunkym) RenderImage(toRender string, address string) (buf []byte) {
	l := bytes.NewBuffer(buf)
	bvar := build_vars(address, toRender)

	request := fm.path.image + "/" + fm.data[address].Image + "/" + toRender
	_, err := os.Stat(request)

	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Cannot find %s", request), err)
	ans, err := ioutil.ReadFile(request)
	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Cannot read %s", request), err)

	tmpl, err := kasia.Parse(string(ans))
	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Cannot parse template for %s", request), err)

	err = tmpl.Run(l, bvar[address])
	fmDaemon.DaemonLog.LogError("Cannot render template", err)

	fm.Increment_Count(address, toRender)
	v := l.Bytes()
	fmDaemon.DaemonLog.LogDebug(fmt.Sprintf("%s: Rendered %s", address, toRender))
	return v
}
Пример #2
0
func (fm *Flunkym) RenderGetDynamic(loc string, address string) []byte {
	var tmp []byte
	dynamic_buf := bytes.NewBuffer(tmp)
	bvar := build_vars(address, loc)
	fname := fm.path.root + loc
	_, err := os.Stat(fname)
	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Could not find %s", fname), err)

	ans, err := ioutil.ReadFile(fname)
	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Could not read %s", fname), err)

	tmpl, err := kasia.Parse(string(ans))
	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Cannot Parse Template for %s", fname), err)

	err = tmpl.Run(dynamic_buf, bvar[address])
	fmDaemon.DaemonLog.LogError(fmt.Sprintf("Cannot execute template render for %s", fname), err)

	fm.Increment_Count(address, loc)

	dynamic := dynamic_buf.Bytes()
	fmDaemon.DaemonLog.LogDebug(fmt.Sprintf("%s Rendered %s", address, loc))
	return dynamic
}