本文整理汇总了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")
}
示例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!")
}
示例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
}
}
示例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++
}
}
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
}
示例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)
}
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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())
}
}
示例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)
}
}
示例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
}