當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ace.Load函數代碼示例

本文整理匯總了Golang中github.com/yosssi/ace.Load函數的典型用法代碼示例。如果您正苦於以下問題:Golang Load函數的具體用法?Golang Load怎麽用?Golang Load使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Load函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/yosssi/ace.Load函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。