コード例 #1
0
ファイル: templates.go プロジェクト: hyb/gowiki
func init() {
	// parse the templates
	wikiTmplSet = template.SetMust(template.ParseSetGlob("templates/*.tmpl"))
	// wikiTmplSet.Funcs(template.FuncMap{

	// })
}
コード例 #2
0
ファイル: web.go プロジェクト: mocchira/digestw
func main() {
	var consumerKey *string = flag.String("consumerkey", "xxx", "")
	var consumerSecret *string = flag.String("consumersecret", "xxx", "")
	var cookieSecret *string = flag.String("cookiesecret", "xxx", "")
	var mongoUrl *string = flag.String("mongourl", "xxx", "")

	flag.Parse()

	consumer = oauth.NewConsumer(
		*consumerKey,
		*consumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "https://api.twitter.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
			AccessTokenUrl:    "https://api.twitter.com/oauth/access_token",
		})
	var err os.Error
	mgoPool, err = mgo.Mongo(*mongoUrl)
	if err != nil {
		panic(err)
	}
	defer mgoPool.Close()

	tplSet = new(template.Set)
	fmap := make(map[string]interface{})
	fmap["cut"] = CutString
	fmap["anchor"] = GenAnchorTagStr
	fmap["sn2url"] = GetTwitterAccountURL
	fmap["ht2url"] = GetSearchResultURL
	fmap["d2url"] = GetDomainURL
	tplSet.Funcs(fmap)
	tplSet = template.SetMust(
		tplSet.ParseTemplateFiles(
			"tpl/index.html",
			"tpl/place.html",
			"tpl/hashtag.html",
			"tpl/url.html",
			"tpl/domain.html",
			"tpl/sn.html",
			"tpl/tab.html",
			"tpl/link.html",
		))

	f, ferr := os.Create("server.log")
	if ferr != nil {
		panic(ferr)
	}
	logger := log.New(f, "", log.Ldate|log.Ltime)
	web.SetLogger(logger)
	web.Config.StaticDir = "../htdocs"
	web.Config.CookieSecret = *cookieSecret

	web.Get("/web/login", onLogin)
	web.Get("/web/callback", onCallback)
	web.Get("/web/stats/([0-9a-zA-Z_]+)/([a-z]+)/([0-9 ]*)", onStats)
	web.Get("/web", onStatsDef)
	web.Run("127.0.0.1:8080")

}
コード例 #3
0
ファイル: index.go プロジェクト: gumbit/go-bootstrap
package handler

import (
	"appengine"
	"http"
	"template"
)

func index(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	model := new(model)
	if err := indexTemplateSet.Execute(w, "Layout", model); err != nil {
		c.Criticalf(`Failed executing template: %v`, err)
		internalServerError(w)
		return
	}
}

var indexTemplateSet = template.SetMust(template.ParseSetFiles(
	"templates/layout.html",
	"templates/index.html"))
コード例 #4
0
ファイル: gotag.go プロジェクト: bmatsuo/gotag
var cmdtemplates = `
{{/* Outputs a shell command given a list of strings (executable + args) */}}
	{{define "cmd"}}{{if ""}}
		{{end}}{{with $cmd := .}}{{range $i, $arg := $cmd}}{{if ""}}
			{{end}}{{if $i}} {{end}}{{quote $arg}}{{end}}{{end}}{{end}}

{{/* Outputs a list of comands .cmds. If .dir is set, the working directory is set with cd*/}}
	{{define "script"}}{{if ""}}
				{{end}}{{if .dir}}cd {{quote .dir}}
{{end}}{{if ""}}
				{{end}}{{range $i, $cmd := .cmds}}{{if $i}}
{{end}}{{if ""}}
				{{end}}{{template "cmd" $cmd}}{{end}}{{end}}
`

var templates = template.SetMust(new(template.Set).Funcs(tfuncs).Parse(cmdtemplates))

func PackagePath(importpath string) string {
	return filepath.Join(runtime.GOROOT(), "src", "pkg", importpath)
}
func ReadablePackagePath(importpath string) string {
	return filepath.Join("$GOROOT", "src", "pkg", importpath)
}

type ShellCmd []string

func CmdTemplateScript(sh script.Scriptor, dir string, cmds ...ShellCmd) script.Script {
	if sh == nil {
		panic("nil scriptor")
	}
	var d string
コード例 #5
0
ファイル: unico.go プロジェクト: licio/unico
var appConfig struct {
	FacebookAppId         string
	FacebookAppSecret     string
	GoogleClientId        string
	GoogleClientSecret    string
	TwitterConsumerKey    string
	TwitterConsumerSecret string
	AppHost               string
	AppDomain             string
	SessionStoreKey       string
}

var (
	templates = template.SetMust(template.ParseSetFiles(
		"404.html",
		"home.html",
		"header.html",
		"footer.html",
		"error.html"))
)

func init() {
	// Read configuration file
	content, err := ioutil.ReadFile("config.json")
	if err == nil {
		err = json.Unmarshal(content, &appConfig)
	}
	if err != nil {
		panic("Can't load configuration")
	}

	// Make sure every conf option has been completed, except
コード例 #6
0
ファイル: polly.go プロジェクト: broady/Polly
type Option struct {
	Text  string
	Image string
	Votes int

	Poll *datastore.Key
	Id   int64
}

type Vote struct {
	Owner  string
	Option *datastore.Key
}

var (
	templates = template.SetMust(template.ParseTemplateGlob("templates/*.html"))
	maxId     = big.NewInt(9223372036854775807)
)

func init() {
	http.HandleFunc("/poll/", pollHandler)
	http.HandleFunc("/vote/", voteHandler)
	http.HandleFunc("/new", newHandler)
	http.HandleFunc("/add", addHandler)
	http.HandleFunc("/thanks", thanksHandler)
	http.HandleFunc("/", listHandler)
}

func voteHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	parts := strings.Split(r.URL.Path, "/")