Beispiel #1
0
func generateRouter() {
	//mkdir for the initiator
	err := os.MkdirAll(*TargetFullPath+"/router/", 0755)
	if err != nil {
		fmt.Println("Unable to create directory, ", err.String())
	}
	f, err := os.Create(*TargetFullPath + "/router/" + "router.go")
	if err != nil {
		fmt.Println(err.String())
	}
	defer f.Close()
	var templ *template.Template
	templ = template.New(nil)
	templ.SetDelims("<%", "%>")
	err = templ.Parse(routerTemplate)
	if err != nil {
		fmt.Println(err.String())
	}
	err = templ.Execute(f, map[string]interface{}{
		"PackageName": *PackageName,
		"ServiceName": *ServiceName,
	})

	if err != nil {
		fmt.Println(err.String())
	}
}
Beispiel #2
0
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
	var buf bytes.Buffer
	if err := t.Execute(data, &buf); err != nil {
		log.Printf("%s.Execute: %s", name, err)
	}
	return buf.Bytes()
}
Beispiel #3
0
/* Apply an HTML template and render.
 *
 * @param templ an HTML template
 * @tempData usually a struct passed to the template
 * @w the response writer that should render the template
 */
func renderTemplateFromFile(context appengine.Context, templ *template.Template, tempData interface{}, w http.ResponseWriter) {
	err := templ.Execute(w, tempData)
	if err != nil {
		serveError(context, w, http.StatusInternalServerError, err) // 500
	}
	return
}
Beispiel #4
0
func template_exec(tpl *template.Template, request uintptr, k_output uint64, k_input uint64) (err string) {
	wr, ok2 := f.Hget(request, k_output).(io.Writer)
	data := f.Hget(request, k_input)
	if !ok2 {
		return fmt.Sprintf("templateExecute_handler input data invalid: tpl {%v}; output {%v, %v}; data {%v}",
			tpl, wr, ok2, data)
	}

	if e := tpl.Execute(data, wr); e != nil {
		return fmt.Sprintf("templateExecute_handler template execution error: %v", e)
	}
	return ""
}
Beispiel #5
0
func render(tmplString string, context interface{}) (string, os.Error) {

	var tmpl *template.Template
	var err os.Error

	if tmpl, err = template.Parse(tmplString, nil); err != nil {
		return "", err
	}

	var buf bytes.Buffer

	tmpl.Execute(context, &buf)
	return buf.String(), nil
}
Beispiel #6
0
func main() {
	prepareCache()
	queryString := parseQueryString(os.Getenv("QUERY_STRING"))
	fmap := template.FormatterMap{"html": template.HTMLFormatter}

	opts := map[string](interface{}){}

	os.Stdout.WriteString("Content-type: text/html\n\n")

	conn := db.PrepareConnection(Cache["db"])

	hdr, _ := template.ParseFile(Cache["tpl:headr"], fmap)

	tmpl := new(template.Template)
	if queryString["forum"] != "" {
		tmpl, _ = template.ParseFile(Cache["tpl:forum"], fmap)
		opts["forum"] = db.Get(conn, db.Forum{}, queryString["forum"])
	} else {
		tmpl, _ = template.ParseFile(Cache["tpl:index"], fmap)
	}

	_ = strconv.Itoa
	c, _ := conf.ReadConfigFile(path.Join(Cache["wd"], "flow.config"))
	opts["version"] = Version
	opts["title"], _ = c.GetString("default", "boardName")

	defer conn.Close()

	if !db.TablesExist(conn) {
		db.SetupForum(conn)
	}

	stmt, _ := conn.Prepare("SELECT id, name, desc FROM forum;")
	db.HandleError(stmt.Exec())

	forums := []db.Forum{}
	if stmt.Next() {
		var f db.Forum
		db.HandleError(stmt.Scan(&f.Id, &f.Name, &f.Desc))
		forums = append(forums, f)
	}

	opts["forums"] = forums
	opts["cwd"] = Cache["cwdir"]

	hdr.Execute(opts, os.Stdout)
	tmpl.Execute(opts, os.Stdout)
}
Beispiel #7
0
func funcToHTML(fset *token.FileSet, t *doce.Func, tpl *template.Template) string {
	b := bytes.NewBuffer(make([]byte, 0, 128))

	recvnostar := t.Recv
	if recvnostar != "" && recvnostar[0] == '*' {
		recvnostar = recvnostar[1:]
	}

	var data = map[string]string{
		"name":       t.Name,
		"code":       codeToString(fset, t.Decl),
		"comment":    commentToHTML(t.Doc),
		"recv":       t.Recv,
		"recvnostar": recvnostar,
	}
	tpl.Execute(b, data)
	return b.String()
}
Beispiel #8
0
/*
 * Prints out the information given to you by ls.Ls depending on the flags
 * given
 *
 */
func printFiles(numArgs int, data [][]ls.FileData, path string, n *bool, temp *template.Template) {
	for pos, dir := range data {
		if pos != 0 {
			path += "/"
			path += dir[0].Name
			fmt.Printf("\n%s:\n", path)
		} else if numArgs > 1 {
			fmt.Printf("%s:\n", path)
		}
		if *n {
			fmt.Printf("total %d\n", totalBlocks(dir))
		}
		for pos1, file := range dir {
			if pos1 != 0 {
				if *n {
					temp.Execute(os.Stdout, file)
				} else {
					fmt.Println(file.Name)
				}
			}
		}
	}
	fmt.Println()
}
Beispiel #9
0
func run(t *template.Template, a interface{}, out io.Writer) {
	if err := t.Execute(out, a); err != nil {
		panic(err)
	}
}
Beispiel #10
0
Datei: ergo.go Projekt: wezm/ergo
func QR(c *http.Conn, req *http.Request, templ *template.Template) {
	templ.Execute(req.FormValue("s"), c)
}