示例#1
0
文件: main.go 项目: hyperation/frozen
func template_load(backend uintptr, request uintptr) (tpl *template.Template, err string) {
	var tpl_str []byte

	// request size
	q_count := f.Hash([]f.Hskel{
		f.Hitem(f.HK_action, f.TYPE_UINT32T, f.ACTION_COUNT),
		f.Hitem(f.HK_buffer, f.TYPE_SIZET, 0),
		f.Hnext(request)})
	f.Backend_pass(backend, q_count)

	str_len, ok := f.Hget(q_count, f.HK_buffer).(uint)
	if !ok || str_len == 0 {
		tpl_str = []byte("")
	} else {
		tpl_str = make([]byte, str_len)

		// read all
		q_read := f.Hash([]f.Hskel{
			f.Hitem(f.HK_action, f.TYPE_UINT32T, f.ACTION_READ),
			f.Hitem(f.HK_buffer, f.TYPE_RAWT, tpl_str),
			f.Hnext(request)})

		f.Backend_pass(backend, q_read)
	}

	tpl, e := template.Parse(string(tpl_str), nil) // TODO BAD BAD BAD
	if e != nil {
		err := fmt.Sprintf("templateLoad_handler template parse error: %v", e)
		return nil, err
	}
	return tpl, ""
}
示例#2
0
文件: main.go 项目: hyperation/frozen
func templateExecute_handler(backend uintptr, request uintptr) int {
	userdata := f.Backend_GetUserdata(backend).(*templateExec_userdata)

	h := f.Hash([]f.Hskel{
		f.Hitem(f.HK_go_template, f.TYPE_GOINTERFACET, nil),
		f.Hnext(request)})
	if e := f.Backend_pass(backend, h); e < 0 {
		return e
	}
	tpl, ok1 := f.Hget(h, f.HK_go_template).(*template.Template)
	if !ok1 {
		log.Print("templateExecute_handler HK(go_template) not supplied")
		return -1
	}

	err := template_exec(tpl, request, userdata.k_output, userdata.k_input)
	if err != "" {
		log.Printf(err)
		return -1
	}

	return 0
}