• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ace.Load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

func main() {
	sl, err := gurren.New([]string{"http://127.0.0.1:9200"}, "test", runtime.NumCPU())
	if err != nil {
		panic(err)
	}

	mux := routes.New()

	// Do handling here

	mux.Get("/", func(rw http.ResponseWriter, r *http.Request) {
		tpl, err := ace.Load("views/layout", "views/index", nil)
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}

		if err := tpl.Execute(rw, nil); err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}
	})

	n := negroni.Classic()

	middleware.Inject(n)
	n.Use(sl)
	n.UseHandler(mux)

	n.Run(":3000")
}
开发者ID:Xe,项目名称:gurren,代码行数:31,代码来源:main.go


示例2: homeHandler

func homeHandler(w http.ResponseWriter, r *http.Request) {

	tpl, _ := ace.Load("templates/base", "templates/home", &ace.Options{DynamicReload: true})
	tpl.Execute(w, []string{"1", "2", "3", "4", "5", "6"})
	// t, _ := template.ParseFiles("templates/home.html", "templates/_header.html")
	// t.Execute(w, "Hello World!")
}
开发者ID:ekkapob,项目名称:hoorayjob,代码行数:7,代码来源:handlers.go


示例3: HandleError

// HandleError renders an error as a HTML page to the user.
func HandleError(rw http.ResponseWriter, r *http.Request, err error) {
	rw.WriteHeader(500)

	if globals.Config.Site.Testing {
		panic(err)
	}

	data := struct {
		Path     string
		Reason   string
		SiteName string
	}{
		Path:     r.URL.String(),
		Reason:   err.Error(),
		SiteName: globals.Config.Site.Name,
	}

	tpl, err := ace.Load("views/layout", "views/error", &ace.Options{
		FuncMap: funcs,
	})
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := tpl.Execute(rw, Wrap(r, data)); err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:stevenbooru,项目名称:stevenbooru,代码行数:31,代码来源:template.go


示例4: handler

func handler(w http.ResponseWriter, r *http.Request) {

	tpl, err := ace.Load("rainbow", "", nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	rand.Seed(time.Now().UnixNano())
	messages := []string{
		"You are awesome,",
		"Pure awesomeness",
		"Coolest person alive:",
		"Literally Awesome:",
		"The amazing",
		"YOLO 420 -",
		"Knows how to tie their shoes:",
		"Makes delicious cakes:",
	}
	selectedMessage := messages[rand.Intn(len(messages))]

	templateErr := tpl.Execute(w, map[string]string{"Message": selectedMessage, "Counter": strconv.Itoa(i), "Url": r.URL.Path[1:]})
	if templateErr != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	} else {
		fmt.Println("Serving " + selectedMessage + " " + r.URL.Path[1:] + " for " + r.RemoteAddr)
		if r.URL.Path[1:] != "favicon.ico" {
			i++
		}
	}
}
开发者ID:Moter8,项目名称:rainbow,代码行数:31,代码来源:rainbow.go


示例5: handler

func handler(w http.ResponseWriter, r *http.Request) {
	tpl, err := ace.Load("base", "inner", nil)
	if err != nil {
		fmt.Printf("error %s", err.Error())
	}
	handleError(err, w)

	// Generate the SSA representation
	if r.Method == "POST" {
		err = r.ParseForm()
		handleError(err, w)

		// Iterate over the checkboxes
		// content[cb.Name] is used in the toSSA algorithm
		cbs := content["cbs"].([]Cb)
		for i, cb := range cbs {
			if r.PostFormValue(cb.Name) == "true" {
				content[cb.Name] = "true"
				cbs[i].Checked = true
			} else {
				content[cb.Name] = "false"
				cbs[i].Checked = false
			}
		}

		ssaBytes := bytes.NewBufferString(r.PostFormValue("source"))
		ssafs, err := toSSA(ssaBytes, "main.go", "main")
		handleError(err, w)
		content["sourceCode"] = r.PostFormValue("source")
		content["ssa"] = ssafs
	}

	err = tpl.Execute(w, content)
	handleError(err, w)
}
开发者ID:akwick,项目名称:ssaview,代码行数:35,代码来源:main.go


示例6: Load

func (a *AceRenderer) Load(paths ...string) (*template.Template, error) {
	var base, inner string
	if len(paths) > 0 {
		base = paths[0]
	} else if len(paths) > 1 {
		inner = paths[1]
	}
	return ace.Load(base, inner, &a.Options)
}
开发者ID:kazukgw,项目名称:goji-active-context,代码行数:9,代码来源:template.go


示例7: Load

// Load calls the `Load` function of the Ace template engine.
func (p *Proxy) Load(basePath, innerPath string, opts *ace.Options) (*template.Template, error) {
	var o *ace.Options

	if opts == nil {
		o = p.Opts
	} else {
		o = opts
	}

	return ace.Load(basePath, innerPath, o)
}
开发者ID:stevenbooru,项目名称:stevenbooru,代码行数:12,代码来源:proxy.go


示例8: handler

func handler(w http.ResponseWriter, r *http.Request) {
	tpl, err := ace.Load("example", "", &ace.Options{DynamicReload: true})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if err := tpl.Execute(w, nil); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:henrylee2cn,项目名称:ace,代码行数:11,代码来源:main.go


示例9: root

func root(c web.C, w http.ResponseWriter, r *http.Request) {
	tpl, err := ace.Load("index", "", nil)
	if err != nil {
		panic(err)
	}
	data := map[string]interface{}{"Title": "Kanban"}
	err = tpl.Execute(w, data)
	if err != nil {
		panic(err)
	}
}
开发者ID:born-in-makuhari,项目名称:kanban,代码行数:11,代码来源:main.go


示例10: doTemplate

func doTemplate(name string, rw http.ResponseWriter, r *http.Request, data interface{}) {
	tpl, err := ace.Load("views/layout", name, nil)
	if err != nil {
		handleError(rw, r, err)
		return
	}

	if err := tpl.Execute(rw, data); err != nil {
		handleError(rw, r, err)
		return
	}
}
开发者ID:Xe,项目名称:xeserv.us,代码行数:12,代码来源:main.go


示例11: ChangelogHandle

// ChangelogHandle changelog page
func ChangelogHandle(w http.ResponseWriter, r *http.Request) {
	tpl, err := ace.Load(common.GetConfig().Server.ViewPath+"/layout", common.GetConfig().Server.ViewPath+"/changelog", nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-type", "text/html")
	if err := tpl.Execute(w, nil); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:slugalisk,项目名称:overrustlelogs,代码行数:13,代码来源:server.go


示例12: f

func f(w http.ResponseWriter, r *http.Request) {

	tpl, err := ace.Load("base", "inner", nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if err := tpl.Execute(w, map[string]string{"Msg": "Hello Ace"}); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:Abdul2,项目名称:acetemplates,代码行数:12,代码来源:ace.go


示例13: main

func main() {
	// create an output directory (the assets subdirectory here because its
	// parent will be created as a matter of course)
	err := os.MkdirAll(TargetAssetsDir, 0755)
	if err != nil {
		log.Fatal(err.Error())
	}

	template, err := ace.Load("index", "", &ace.Options{
		DynamicReload: true,
		FuncMap:       templateFuncMap(),
	})
	if err != nil {
		log.Fatal(err.Error())
	}

	db, err := wgt2.LoadDatabase(DBFilename)
	if err != nil {
		log.Fatal(err.Error())
	}

	var artists []*wgt2.Artist
	for _, artist := range db.Artists.Data {
		artists = append(artists, artist)
	}

	// Go doesn't exactly make sorting easy ...
	sort.Sort(artistSlice(artists))

	var playlists []*wgt2.Playlist
	for _, playlist := range db.Playlists.Data {
		playlists = append(playlists, playlist)
	}

	file, err := os.Create(TargetDir + "index")
	if err != nil {
		log.Fatal(err.Error())
	}
	defer file.Close()

	writer := bufio.NewWriter(file)
	defer writer.Flush()

	data := map[string]interface{}{
		"artists":   artists,
		"playlists": playlists,
	}
	if err := template.Execute(writer, data); err != nil {
		log.Fatal(err.Error())
	}
}
开发者ID:brandur,项目名称:wgt2,代码行数:51,代码来源:main.go


示例14: WrapperHandle

// WrapperHandle static html log wrapper
func WrapperHandle(w http.ResponseWriter, r *http.Request) {
	tpl, err := ace.Load(common.GetConfig().Server.ViewPath+"/layout", common.GetConfig().Server.ViewPath+"/wrapper", nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-type", "text/html; charset=UTF-8")
	path := r.URL.Path + ".txt"
	if r.URL.RawQuery != "" {
		path += "?" + r.URL.RawQuery
	}
	if err := tpl.Execute(w, struct{ Path string }{Path: path}); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
开发者ID:slugalisk,项目名称:overrustlelogs,代码行数:16,代码来源:server.go


示例15: compileResultFromFile

func compileResultFromFile(baseFile, innerFile string) (string, error) {
	base := baseFile[:len(baseFile)-len(filepath.Ext(baseFile))]

	var inner string
	if len(innerFile) > 0 {
		inner = innerFile[:len(innerFile)-len(filepath.Ext(innerFile))]
	}
	name := base + ":" + inner

	tpl, err := ace.Load(base, inner, nil)
	if err != nil {
		return "", err
	}
	return tpl.Lookup(name).Tree.Root.String(), nil
}
开发者ID:henrylee2cn,项目名称:ace,代码行数:15,代码来源:main.go


示例16: Render

func (c controller) Render(w http.ResponseWriter, view string) {
	options := &ace.Options{Asset: Asset}

	tpl, err := ace.Load("backend/views/layout", view, options)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	err = tpl.Execute(w, nil)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
}
开发者ID:sai-lab,项目名称:mouryou-web,代码行数:15,代码来源:controller.go


示例17: DoTemplate

// DoTemplate does a template with the given data to pass to it. It will be
// wrapped as .Data.
func DoTemplate(name string, rw http.ResponseWriter, r *http.Request, data interface{}) {
	tpl, err := ace.Load("views/layout", "views/"+name, &ace.Options{
		FuncMap: funcs,
	})
	if err != nil {
		HandleError(rw, r, err)
		return
	}

	wrapped := Wrap(r, data)

	if err := tpl.Execute(rw, wrapped); err != nil {
		HandleError(rw, r, err)
		return
	}
}
开发者ID:stevenbooru,项目名称:stevenbooru,代码行数:18,代码来源:template.go


示例18: indexHandler

func indexHandler(w http.ResponseWriter, r *http.Request) {
	var err error
	defer func() {
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
	}()

	if r.Method != "GET" {
		http.Error(w, "Method not allowed", 405)
		return
	}

	tpl, err := ace.Load("index", "", &ace.Options{DynamicReload: true})
	if err != nil {
		return
	}

	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	err = tpl.Execute(w, r.Host)
}
开发者ID:s-urbaniak,项目名称:chat,代码行数:21,代码来源:main.go


示例19: homeHandler

func homeHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	data := map[string]string{
		"isDevelopment":   appEngineEnvironment("isDevelopment"),
		"isProduction":    appEngineEnvironment("isProduction"),
		"currentHostname": appengine.DefaultVersionHostname(c),
	}

	tpl, err := ace.Load("base", "inner", &ace.Options{
		BaseDir:       "views",
		DynamicReload: true})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := tpl.Execute(w, data); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:aficiomaquinas,项目名称:i18n-cd-mx,代码行数:22,代码来源:server.go


示例20: handleError

func handleError(rw http.ResponseWriter, r *http.Request, err error) {
	rw.WriteHeader(500)

	data := struct {
		Path   string
		Reason string
	}{
		Path:   r.URL.String(),
		Reason: err.Error(),
	}

	tpl, err := ace.Load("views/layout", "views/error", nil)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := tpl.Execute(rw, data); err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:Xe,项目名称:xeserv.us,代码行数:22,代码来源:main.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang client.New函数代码示例发布时间:2022-05-28
下一篇:
Golang plugin.Env类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap