<file_sep>package main

import (
	//"fmt"
	//"time"
	"net/http"
	//."github.com/vycb/gorazortpl/tpl/bench"
	"github.com/vycb/gorazortpl/tpl/helper"
	."github.com/vycb/gorazortpl/tpl"
)


func main() {

	http.HandleFunc("/", root)
	http.ListenAndServe(":8080", nil)

	//fmt.Println(Home(2, &helper.User{"UserName", "User@email", "User Intro"}))
	//fmt.Println(Bench(&Page{"UserName", []string{"User Intro","red","black"}, time.Now().Year()}))
}

func root(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte(Home(2, &helper.User{"UserName", "User@email", "User Intro"})))
	//fmt.Println(Bench(&Page{"UserName", []string{"User Intro","red","black"}, time.Now().Year()}))

	//page := &Page{
	//	Title: "Bob",
	//	FavoriteColors: []string{"blue", "green", "mauve"},
	//	Year: time.Now().Year(),
	//}

}

<file_sep>package tpl

import (
	"bytes"
	"github.com/sipin/gorazor/gorazor"
	. "github.com/vycb/gorazortpl/tpl/bench"
	"strings"
)

func Bench(p *Page) string {
	var _buffer bytes.Buffer
	_buffer.WriteString(gorazor.HTMLEscape(Header(p)))
	_buffer.WriteString("\n<h1>Hello ")
	_buffer.WriteString(gorazor.HTMLEscape(strings.TrimSpace(p.Title)))
	_buffer.WriteString(" !</h1>\n\n<p>Here's a list of your favorite colors:</p>\n<ul>\n\t")
	for _, colorName := range p.FavoriteColors {

		_buffer.WriteString("<li>")
		_buffer.WriteString(gorazor.HTMLEscape(colorName))
		_buffer.WriteString("</li>")

	}
	_buffer.WriteString("\n</ul>")
	_buffer.WriteString(gorazor.HTMLEscape(Footer(p)))

	return _buffer.String()
}
<file_sep>package bench

import (
	"bytes"
	"github.com/sipin/gorazor/gorazor"
)

func Footer(p *Page) string {
	var _buffer bytes.Buffer
	_buffer.WriteString("\n\n<div>")
	_buffer.WriteString(gorazor.HTMLEscape(p.Year))
	_buffer.WriteString(" Year</div>\n</body>\n</html>")

	return _buffer.String()
}
<file_sep>package bench

type Page struct {
	Title          string
	FavoriteColors []string
	Year           int
}<file_sep>package helper

type User struct {
	Name string
	Email string
	Intro string
}<file_sep>package bench

import (
	"bytes"
	"github.com/sipin/gorazor/gorazor"
)

func Header(p *Page) string {
	var _buffer bytes.Buffer
	_buffer.WriteString("\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n\t<meta charset=\"UTF-8\">\n\t<title>")
	_buffer.WriteString(gorazor.HTMLEscape(p.Title))
	_buffer.WriteString("</title>\n</head>\n<body>")

	return _buffer.String()
}
<file_sep>package main

import (
	"fmt"
	"testing"
	"time"
	."github.com/vycb/gorazortpl/tpl/bench"
	."github.com/vycb/gorazortpl/tpl"
)

func BenchmarkMain(*testing.B) {
	// Parallel benchmark for text/template.Template.Execute on a single object.
	testing.Benchmark(func(b *testing.B) {

		page := &Page{
			Title: "Bob",
			FavoriteColors: []string{"blue", "green", "mauve"},
			Year: time.Now().Year(),
		}

		// RunParallel will create GOMAXPROCS goroutines
		// and distribute work among them.
		b.RunParallel(func(pb *testing.PB) {
			// Each goroutine has its own bytes.Buffer.

			for pb.Next() {
				// The loop body is executed b.N times total across all goroutines.

				 fmt.Println(Bench(page))
			}
		})

	})
}
