当前位置: 首页>>代码示例>>Golang>>正文


Golang template.ParseGlob函数代码示例

本文整理汇总了Golang中html/template.ParseGlob函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseGlob函数的具体用法?Golang ParseGlob怎么用?Golang ParseGlob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ParseGlob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: watchAndParseTemplates

func watchAndParseTemplates() {

	templatesDir := utils.FindDir("web/templates")
	l4g.Debug(utils.T("web.parsing_templates.debug"), templatesDir)
	var err error
	if Templates, err = template.ParseGlob(templatesDir + "*.html"); err != nil {
		l4g.Error(utils.T("web.parsing_templates.error"), err)
	}

	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		l4g.Error(utils.T("web.create_dir.error"), err)
	}

	go func() {
		for {
			select {
			case event := <-watcher.Events:
				if event.Op&fsnotify.Write == fsnotify.Write {
					l4g.Info(utils.T("web.reparse_templates.info"), event.Name)
					if Templates, err = template.ParseGlob(templatesDir + "*.html"); err != nil {
						l4g.Error(utils.T("web.parsing_templates.error"), err)
					}
				}
			case err := <-watcher.Errors:
				l4g.Error(utils.T("web.dir_fail.error"), err)
			}
		}
	}()

	err = watcher.Add(templatesDir)
	if err != nil {
		l4g.Error(utils.T("web.watcher_fail.error"), err)
	}
}
开发者ID:sugaofeng,项目名称:platform,代码行数:35,代码来源:web.go

示例2: watchAndParseTemplates

func watchAndParseTemplates() {

	templatesDir := utils.FindDir("web/templates")
	l4g.Debug("Parsing templates at %v", templatesDir)
	var err error
	if Templates, err = template.ParseGlob(templatesDir + "*.html"); err != nil {
		l4g.Error("Failed to parse templates %v", err)
	}

	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		l4g.Error("Failed to create directory watcher %v", err)
	}

	go func() {
		for {
			select {
			case event := <-watcher.Events:
				if event.Op&fsnotify.Write == fsnotify.Write {
					l4g.Info("Re-parsing templates because of modified file %v", event.Name)
					if Templates, err = template.ParseGlob(templatesDir + "*.html"); err != nil {
						l4g.Error("Failed to parse templates %v", err)
					}
				}
			case err := <-watcher.Errors:
				l4g.Error("Failed in directory watcher %v", err)
			}
		}
	}()

	err = watcher.Add(templatesDir)
	if err != nil {
		l4g.Error("Failed to add directory to watcher %v", err)
	}
}
开发者ID:jianyongchen,项目名称:platform,代码行数:35,代码来源:web.go

示例3: LoadHTMLGlob

func (engine *Engine) LoadHTMLGlob(pattern string) {
	if IsDebugging() {
		debugPrintLoadTemplate(template.Must(template.ParseGlob(pattern)))
		engine.HTMLRender = render.HTMLDebug{Glob: pattern}
	} else {
		templ := template.Must(template.ParseGlob(pattern))
		engine.SetHTMLTemplate(templ)
	}
}
开发者ID:jakerandell,项目名称:wedding,代码行数:9,代码来源:gin.go

示例4: startServer

func startServer(port string) {
	manager = session.NewSessionManager(nil)

	manager.OnStart(func(session *session.Session) {
		l.Debug("Session Manager: Started a new session.\n")
	})
	manager.OnEnd(func(session *session.Session) {
		l.Debug("Session Manager: Destroyed a session.\n")
	})
	manager.SetTimeout(10)

	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static/"))))
	http.HandleFunc("/data", DataHandler)
	http.HandleFunc("/", IndexHandler)
	http.HandleFunc("/login", LoginHandler)
	var e error

	t, e = template.ParseGlob("web/templates/*.tmpl")

	if e != nil {
		l.Fatal("Unable to parse templates: %s\n", e.Error())
	}

	e = http.ListenAndServe(port, nil)

	if e != nil {
		l.Fatal("Unable to start embeeded webserver: %s\n", e.Error())
	}
}
开发者ID:alouca,项目名称:gosyslog,代码行数:29,代码来源:webserver.go

示例5: init

func init() {
	tpl, _ = template.ParseGlob("*.html")
	http.HandleFunc("/", main)

	//serve the css files in a file server instead of uploading it to gcs and querying it.
	http.Handle("/css/", http.StripPrefix("/css", http.FileServer(http.Dir("css"))))
}
开发者ID:jgtaruc,项目名称:GoLang130,代码行数:7,代码来源:main.go

示例6: main

func main() {
	tpl = template.Must(template.ParseGlob("templates/*.gohtml"))

	f, err := os.OpenFile("logfile.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0664)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	log.SetOutput(f)

	client, err = as.NewClient("127.0.0.1", 3000)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	router := httprouter.New()
	router.GET("/", index)
	router.GET("/login", loginPage)
	router.POST("/login", login)
	router.GET("/logout", logout)
	router.GET("/create", createPage)
	router.POST("/create", create)
	err = http.ListenAndServe(":9000", router)
	if err != nil {
		panic(err)
	}
}
开发者ID:Oralordos,项目名称:Digitalocean-Golang-and-Aerospike,代码行数:28,代码来源:main.go

示例7: ParseGlob

func ParseGlob(pattern string) (Template, error) {
	if Debug {
		return (&reloadTemplate{}).ParseGlob(pattern)
	}
	t, err := htmlTmpl.ParseGlob(pattern)
	return &instantTemplate{t}, err
}
开发者ID:orian,项目名称:template,代码行数:7,代码来源:template.go

示例8: adminUsersHandler

func adminUsersHandler(w http.ResponseWriter, r *http.Request, admin Location) {
	isAuth(w, r, admin, "admin")
	if r.Method == "POST" {
		var user httpauth.UserData
		user.Username = r.PostFormValue("username")
		user.Email = r.PostFormValue("email")
		password := r.PostFormValue("password")
		user.Role = r.PostFormValue("role")
		if err := aaa.Register(w, r, user, password); err != nil {
			// maybe something
		}
	}

	if user, err := aaa.CurrentUser(w, r); err == nil {
		type data struct {
			User  httpauth.UserData
			Roles map[string]httpauth.Role
			Users []httpauth.UserData
			Msg   []string
		}
		messages := aaa.Messages(w, r)
		users, err := backend.Users()
		if err != nil {
			panic(err)
		}
		d := data{User: user, Roles: roles, Users: users, Msg: messages}
		var templates = template.Must(template.ParseGlob("admin/templates/*"))
		t_err := templates.ExecuteTemplate(w, "manage-accounts.html", d)
		if t_err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
	}
}
开发者ID:topiary-io,项目名称:topiary,代码行数:33,代码来源:auth.go

示例9: WrapHandlerImpl

// Wraps other http handlers. Creates context object, recovers from panics, etc.
func WrapHandlerImpl(fn AppHandlerFunc, parseForm bool) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		c := &Context{}

		// See http://blog.golang.org/2010/08/defer-panic-and-recover.html.
		defer func() {
			if data := recover(); data != nil {
				c.Aec().Errorf(fmt.Sprint(data))
				ServeError(w, data)
			}
		}()

		// Initialize the request context object.
		c.SetAec(appengine.NewContext(r))
		CheckError(ReadSession(r, c))
		if msg, err := ConsumeFlash(w, r); err != nil && err != http.ErrNoCookie {
			ServeError(w, err)
			return
		} else {
			c.SetFlash(msg)
		}

		if parseForm {
			CheckError(r.ParseForm())
		}

		if appengine.IsDevAppServer() {
			tmpl = template.Must(template.ParseGlob("templates/*.html"))
			text_tmpl = text_template.Must(text_template.ParseGlob("templates/*.txt"))
		}
		fn(w, r, c)
	}
}
开发者ID:asadovsky,项目名称:tadue,代码行数:34,代码来源:util.go

示例10: init

// set everything up.
func init() {
	tpl = template.Must(template.ParseGlob("*.html"))
	resourceHandler("css")
	resourceHandler("img")
	resourceHandler("photos")
	http.HandleFunc("/", mainPage)
}
开发者ID:ljmeyers80529,项目名称:CSCI130,代码行数:8,代码来源:main.go

示例11: actionHome

func actionHome(w http.ResponseWriter, req *http.Request) {

	var templActionHome *template.Template = template.Must(
		template.ParseGlob("templates/home/*.html"))

	lay := getLayoutTemplates()
	wr := &HtmlContainer{}

	// templActionHome.Funcs(template.FuncMap{"len": Len})
	data := HtmlAssigner{
		"List": getEntryList("", 10),
		"Test": "Test",
	}

	err := templActionHome.Execute(wr, data)
	if err != nil {
		fmt.Errorf("%v", err)
	}

	lay.New("title").Parse("Najnowsze wpisy - " + config.GetStringDef("page", "title", ""))

	err = lay.Execute(w, wr.getHtml())
	if err != nil {
		fmt.Errorf("%v", err)
	}
}
开发者ID:DeyV,项目名称:go-newsagg,代码行数:26,代码来源:actions.go

示例12: loadTemplates

func loadTemplates() (templates *template.Template, err error) {
	if !*devMode && t != nil {
		return t, nil
	}
	t, err = template.ParseGlob("templates/*")
	return t, err
}
开发者ID:billyboar,项目名称:GCSolutions,代码行数:7,代码来源:templates.go

示例13: listenForChanges

//reload templates on modify
func listenForChanges() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}

	done := make(chan bool)

	// Process events
	go func() {
		for {
			select {
			case ev := <-watcher.Event:
				log.Println("event:", ev)
				//recompile templates
				templates = template.Must(template.ParseGlob("templates/*.html"))
			case err := <-watcher.Error:
				log.Println("error:", err)
			}
		}
	}()

	err = watcher.Watch("templates/")
	if err != nil {
		log.Fatal(err)
	}

	<-done

	watcher.Close()
}
开发者ID:rdallman,项目名称:aumdug-web,代码行数:32,代码来源:server.go

示例14: helperMustLoadTemplates

func helperMustLoadTemplates() *template.Template {
	t, err := template.ParseGlob(config.resourceDir + "/views/posts/*.html")
	if err != nil {
		panic(err.Error())
	}
	return t
}
开发者ID:skyec,项目名称:esblog,代码行数:7,代码来源:post_controller.go

示例15: initTemplate

func initTemplate() *template.Template {
	t, parseErr := template.ParseGlob("template/*.tmpl")
	if parseErr != nil {
		log.Panicln("NisePostGo: ", parseErr)
	}
	return t
}
开发者ID:nise-nabe,项目名称:NisePostGo,代码行数:7,代码来源:nisepost.go


注:本文中的html/template.ParseGlob函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。