示例#1
0
func init() {
	for _, tmpl := range []string{"index", "404", "edit"} {
		templates[tmpl] = template.MustParseFile("/var/www/apps/gophertimes/templates/"+tmpl+".html", nil)
	}
	templates["all.rss"] = template.MustParseFile("/var/www/apps/gophertimes/templates/all.rss", nil)

	/*        argv := []string{
	              "6g",
	              "-V",
	              "/dev/null",
	              "EOF",
	          }
	          exe, err := exec.LookPath(argv[0])
	          if err != nil {
	             fmt.Println("run:", err)
	          }
	          cmd, err := exec.Run(exe, argv, nil, "", exec.DevNull, exec.Pipe, exec.DevNull)
	          if err != nil {
	              fmt.Println("run:", err)
	          }
	          buf, err := ioutil.ReadAll(cmd.Stdout)
	*/
	goVersion = "release.r57.1 8294"

}
示例#2
0
func readFixture(filename string, data interface{}) string {
	buf := bytes.NewBufferString("")

	template.MustParseFile(fmt.Sprintf("fixture/%s.xml.gt", filename), nil).Execute(buf, data)

	return buf.String()
}
示例#3
0
文件: app.go 项目: vichetuc/appgo
// Cache templates
func getTemplate(name string) *template.Template {
	tmp := server.Templates[name]
	if tmp == nil {
		tmp = template.MustParseFile(getTemplateName(name), filters)
		server.Templates[name] = tmp
	}
	return tmp
}
示例#4
0
func init() {
	/*cache templates*/
	for _, tmpl := range []string{"index", "list", "show"} {
		templates[tmpl] = template.MustParseFile(tmpl+".html", nil)
	}

	/*setup handlers*/
	http.HandleFunc("/", makeHandler(index))
	http.HandleFunc("/upload", makeHandler(upload))
	http.HandleFunc("/show/", makeHandler(show))
	http.HandleFunc("/img", makeHandler(img))
	http.HandleFunc("/list", makeHandler(list))
}
示例#5
0
文件: template.go 项目: newblue/gonew
//  Given a filename and dictionary context, create a context dict+("file"=>filename),
//  and read a template specified by relpath. See GetTemplatePath().
func ParseTemplate(filename string, dict map[string]string, relpath []string) (string, os.Error) {
	var tpath = GetTemplatePath(relpath)
	if tpath == "" {
		return "", NoTemplateError
	}
	if DEBUG && DEBUG_LEVEL > 0 {
		log.Printf("scanning: %s", tpath)
		if DEBUG_LEVEL > 1 {
			log.Printf("context:\n%v", dict)
		}
	}
	var template = template.MustParseFile(tpath, nil)
	var buff = bytes.NewBuffer(make([]byte, 0, 1<<20))
	var errTExec = template.Execute(buff, combinedData(dict, extraData(filename)))
	return buff.String(), errTExec
	//return mustache.RenderFile(tpath, dict, map[string]string{"file":filename, "test":TestName(filename)}), nil
}
示例#6
0
package main

import (
	"container/vector"
	"ext/direct"
	"ext/jsb2"
	"fmt"
	"http"
	"io/ioutil"
	"log"
	"os"
	"template"
)

var (
	TEMPLATE  = template.MustParseFile("example/index.html", nil)
	EXTJSROOT string
)

func init() {
	var getenvErr os.Error
	EXTJSROOT, getenvErr = os.Getenverror("EXTJSROOT")
	if getenvErr != nil {
		panic(getenvErr)
	}
}

// view example at http://localhost:8080/ with firebug console
// ext docs at http://localhost:8080/ext/docs/
// for go docs run "godoc -http=:6060" and hit http://localhost:6060/
func main() {
示例#7
0
}

func root(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	q := datastore.NewQuery("Greeting").Order("-Date").Limit(10)
	greetings := make([]Greeting, 0, 10)
	if _, err := q.GetAll(c, &greetings); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}
	if err := guestbookTemplate.Execute(w, greetings); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
	}
}

var guestbookTemplate = template.MustParseFile("views/guestbook.html", nil)

func sign(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	g := Greeting{
		Content: r.FormValue("content"),
		Date:    datastore.SecondsToTime(time.Seconds()),
	}
	if u := user.Current(c); u != nil {
		g.Author = u.String()
	}
	_, err := datastore.Put(c, datastore.NewIncompleteKey("Greeting"), &g)
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}
示例#8
0
文件: http.go 项目: nictuku/gomine
func init() {
	for _, tmpl := range []string{"base"} {
		templates[tmpl] = template.MustParseFile("templates/"+tmpl+".html", nil)
	}
}
// data that gets processed by the html template
type HuntTemplateData struct {
	User               string
	Error              string
	SuppressAnswerBox  bool
	SuppressBackButton bool
	*HuntDirectoryEntry
	DebugHuntData *Hunt
	CurrentState  *State
}

func init() {
	http.HandleFunc(huntPath, handleHunt)
}

var huntTemplate = template.MustParseFile(huntTemplateFileName, template.FormatterMap{"dstime": dstimeFormatter})

func handleHunt(w http.ResponseWriter, r *http.Request) {
	var td HuntTemplateData
	var err os.Error
	defer recoverUserError(w, r)
	c = appengine.NewContext(r)

	td.User = requireAnyUser(w, r)
	LogAccess(r, td.User)
	if td.User == "" {
		panic("requireAnyUser did not return a username")
	}

	// get hunt name from URL path
	huntSearchName := strings.Split(strings.Replace(r.URL.Path, huntPath, "", 1), "/", 2)[0]
示例#10
0
文件: server.go 项目: egonelbre/sivq
	Threshold      float64
	RotationStride float64
	MatchStride    int
	MatchingOffset int
	GammaAdjust    float64
	AverageBias    float64
}

type Work struct {
	conn   *websocket.Conn
	input  *ProcessInput
	stopCh chan bool
}

var (
	uploadTemplate = template.MustParseFile(TemplateDir+"upload.html", nil)
	errorTemplate  = template.MustParseFile(TemplateDir+"error.html", nil)
	workChan       = make(chan Work)
)

/*
 * Check for error and panic if needed
 */
func checkError(e os.Error) {
	if e != nil {
		panic(e)
	}
}

/*
 * Index page handler
示例#11
0
func parseTemplate(filename string) *Template {
	return &Template{
		t:        template.MustParseFile(path.Join("template", filename), formatterMap),
		mimeType: mime.TypeByExtension(path.Ext(filename))}
}
示例#12
0
文件: view.go 项目: snim2/howl
// Used only for debugging.
import (
	"reflect"
)

import (
	"controller"
	"model"
)

/* HTML templates.
 *
 * These are stored in the top level directory of the app.
 */
var (
	signInTemplate  = template.MustParseFile("sign.html", nil)
	streamTemplate  = template.MustParseFile("stream.html", nil)
	dashTemplate    = template.MustParseFile("dashboard.html", nil)
	profileTemplate = template.MustParseFile("profile.html", nil)
)

/* Serve a Not Found page.
 *
 * TODO: Add a styled template.
 */
func serve404(w http.ResponseWriter) {
	w.WriteHeader(http.StatusNotFound)
	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	io.WriteString(w, "Not Found")
	log.Println("ERROR: 404 Not Found")
}
示例#13
0
)

// config returns the configuration information for OAuth and Buzz.
func config(host string) *oauth.Config {
	return &oauth.Config{
		ClientId:     CLIENT_ID,
		ClientSecret: CLIENT_SECRET,
		Scope:        "https://www.googleapis.com/auth/buzz",
		AuthURL:      "https://accounts.google.com/o/oauth2/auth",
		TokenURL:     "https://accounts.google.com/o/oauth2/token",
		RedirectURL:  fmt.Sprintf("http://%s/post", host),
	}
}

var (
	uploadTemplate = template.MustParseFile("upload.html", nil)
	editTemplate   *template.Template // set up in init()
	postTemplate   = template.MustParseFile("post.html", nil)
	errorTemplate  = template.MustParseFile("error.html", nil)
)

// Because App Engine owns main and starts the HTTP service,
// we do our setup during initialization.
func init() {
	http.HandleFunc("/", errorHandler(upload))
	http.HandleFunc("/edit", errorHandler(edit))
	http.HandleFunc("/img", errorHandler(img))
	http.HandleFunc("/share", errorHandler(share))
	http.HandleFunc("/post", errorHandler(post))
	editTemplate = template.New(nil)
	editTemplate.SetDelims("{{{", "}}}")
示例#14
0
func init() {
	for _, tmpl := range []string{"edit", "view"} {
		templates[tmpl] = template.MustParseFile(tmpl+".html", nil)
	}
}
示例#15
0
var step1 = Step{
	"Double my input",
	"Write a function that doubles its input.",
	"func fn(i int) int {\n}",
	TestData{Setup: "n := 1", Args: "n", Expect: "2"},
}

func stepHandler(w http.ResponseWriter, r *http.Request) {
	err := stepTemplate.Execute(w, step1)
	if err != nil {
		log.Print(err)
	}
}

var stepTemplate = template.MustParseFile("tmpl/step.html", nil)

func testHandler(w http.ResponseWriter, r *http.Request) {
	// read user code
	userCode := new(bytes.Buffer)
	defer r.Body.Close()
	if _, err := userCode.ReadFrom(r.Body); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}
	// put user code in harness
	t := step1.Test
	t.UserCode = userCode.String()
	code := new(bytes.Buffer)
	if err := TestHarness.Execute(code, t); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
示例#16
0
文件: action.go 项目: bedwards/gowiki
func createHttpGetAction(loader common.PageLoader, tmplFilename string, loadErrHandler LoadErrHandler) Action {
	tmpl := template.MustParseFile(tmplFilename, nil)
	return &httpGetAction{loader, tmpl, loadErrHandler}
}
示例#17
0
	"http"
	"strconv"
	"template"
	"time"
)

type Game struct {
	P1      string
	P1score int
	P2      string
	P2score int
	Played  datastore.Time
}

var (
	appTemplate = template.MustParseFile("app.html", nil)
)

func init() {
	http.HandleFunc("/games", games)
	http.HandleFunc("/", root)
}

func initProtectedPage(w http.ResponseWriter, r *http.Request) (c appengine.Context, u *user.User, die bool) {
	die = false

	c = appengine.NewContext(r)

	u = user.Current(c)

	if u == nil {