本文整理匯總了Golang中github.com/companieshouse/gotcha/http.Session.Render方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Render方法的具體用法?Golang Session.Render怎麽用?Golang Session.Render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/companieshouse/gotcha/http.Session
的用法示例。
在下文中一共展示了Session.Render方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: render_import
func render_import(session *http.Session) {
html, _ := session.RenderTemplate("import.html")
session.Stash["Page"] = "Import"
session.Stash["ImportAvailable"] = config.ImportAvailable
session.Stash["Content"] = template.HTML(html)
session.Render("layout.html")
}
示例2: settings
func settings(session *http.Session) {
session.Stash["Title"] = "SmartPAN Settings"
html, _ := session.RenderTemplate("settings.html")
session.Stash["Page"] = "Settings"
session.Stash["Content"] = template.HTML(html)
session.Render("layout.html")
}
示例3: help
func help(session *http.Session) {
session.Stash["Title"] = "SmartPAN Help"
html, _ := session.RenderTemplate("help.html")
session.Stash["Page"] = "Help"
session.Stash["Content"] = template.HTML(html)
session.Render("layout.html")
}
示例4: import2
func import2(session *http.Session) {
if !config.ImportAvailable {
session.Render("error.html")
session.Stash["GoPANError"] = "Import is currently unavailable"
return
}
session.Stash["Page"] = "Import"
session.Stash["Title"] = "Import job " + session.Stash["jobid"].(string)
job := imports[session.Stash["jobid"].(string)]
session.Stash["Job"] = job
html, _ := session.RenderTemplate("import2.html")
session.Stash["Content"] = template.HTML(html)
session.Render("layout.html")
}
示例5: delete_file
func delete_file(session *http.Session) {
session.Stash["Title"] = "Delete file"
html, _ := session.RenderTemplate("delete.html")
repo := session.Stash["repo"].(string)
file := session.Stash["file"].(string)
auth1 := session.Stash["auth1"].(string)
auth2 := session.Stash["auth2"].(string)
auth3 := session.Stash["auth3"].(string)
fname := config.CacheDir + "/" + repo + "/" + auth1 + "/" + auth2 + "/" + auth3 + "/" + file
if _, err := os.Stat(fname); err != nil {
session.RenderNotFound()
return
}
// Remove file from indexes
for f, _ := range indexes {
if _, ok := indexes[f][repo]; !ok {
continue
}
if _, ok := indexes[f][repo].Authors[auth3]; !ok {
continue
}
if _, ok := indexes[f][repo].Authors[auth3].Packages[file]; !ok {
continue
}
log.Debug("Removing from index: %s", repo)
pkg := indexes[f][repo].Authors[auth3].Packages[file]
delete(indexes[f][repo].Authors[auth3].Packages, file)
if len(indexes[f][repo].Authors[auth3].Packages) == 0 {
log.Debug("Removing author")
delete(indexes[f][repo].Authors, auth3)
}
if len(indexes[f][repo].Authors) == 0 {
log.Debug("Removing index")
delete(indexes[f], repo)
}
if auth, ok := mapped[repo][auth1][auth2][auth3]; ok {
if len(auth.Packages) == 0 {
log.Debug("Removing author from mapped index")
delete(mapped[repo][auth1][auth2], auth3)
delete(mapped[repo]["*"][auth2], auth3)
delete(mapped[repo][auth1]["**"], auth3)
delete(mapped[repo]["*"]["**"], auth3)
}
if len(mapped[repo][auth1][auth2]) == 0 {
log.Debug("Removing auth1/auth2 from mapped index")
delete(mapped[repo][auth1], auth2)
}
if len(mapped[repo]["*"][auth2]) == 0 {
log.Debug("Removing author **/auth2 from mapped index")
delete(mapped[repo][auth1], auth2)
}
if len(mapped[repo][auth1]["**"]) == 0 {
log.Debug("Removing author auth1/** from mapped index")
delete(mapped[repo][auth1], auth2)
}
if len(mapped[repo]["*"]["**"]) == 0 {
log.Debug("Removing author */** from mapped index")
delete(mapped[repo][auth1], auth2)
}
if len(mapped[repo]["*"]) == 0 {
log.Debug("Removing author * from mapped index")
delete(mapped[repo][auth1], auth2)
}
if len(mapped[repo][auth1]) == 1 {
log.Debug("Removing author auth1 from mapped index")
delete(mapped[repo], auth1)
}
if len(mapped[repo]) == 1 {
log.Debug("Removing repo from mapped index")
delete(mapped, repo)
}
}
for _, prov := range pkg.Provides {
parts := strings.Split(prov.Name, "::")
// TODO remove from packages/idxpackages
if ctx, ok := packages[parts[0]]; ok {
parts = parts[1:]
for len(parts) > 0 {
if c, ok := ctx.Children[parts[0]]; ok {
ctx = c
} else {
log.Debug("Package not found in packages: %s", parts)
break
}
parts = parts[1:]
}
if len(parts) == 0 {
//.........這裏部分代碼省略.........
示例6: search
func search(session *http.Session) {
if q, ok := session.Request.Form()["q"]; ok {
query := strings.ToLower(q[0])
session.Stash["Query"] = q[0]
results := make([]*SearchResult, 0)
var lock sync.Mutex
tStart := time.Now().UnixNano()
log.Trace("Searching for [%s]", query)
var wg sync.WaitGroup
for fname, _ := range indexes {
log.Trace("=> Searching file: %s", fname)
for _, idx := range indexes[fname] {
log.Trace("=> Searching index: %s", idx.Name)
wg.Add(1)
go func(idx *gopan.Source) {
defer wg.Done()
if strings.Contains(strings.ToLower(idx.Name), query) {
lock.Lock()
results = append(results, &SearchResult{
Name: idx.Name,
Type: "Index",
URL: idx.Name,
Obj: idx,
Glyph: "list",
})
lock.Unlock()
}
for _, auth := range idx.Authors {
wg.Add(1)
go func(idx *gopan.Source, auth *gopan.Author) {
defer wg.Done()
if strings.Contains(strings.ToLower(auth.Name), query) {
lock.Lock()
results = append(results, &SearchResult{
Name: auth.Name,
Type: "Author",
URL: idx.Name + "/authors/id/" + auth.Name[:1] + "/" + auth.Name[:2] + "/" + auth.Name,
Obj: auth,
Glyph: "user",
})
lock.Unlock()
}
for _, pkg := range auth.Packages {
if strings.Contains(strings.ToLower(pkg.Name), query) {
lock.Lock()
results = append(results, &SearchResult{
Name: pkg.Name,
Type: "Module",
URL: idx.Name + "/authors/id/" + auth.Name[:1] + "/" + auth.Name[:2] + "/" + auth.Name + "/" + pkg.Name,
Obj: pkg,
Glyph: "compressed",
})
lock.Unlock()
}
for _, prov := range pkg.Provides {
if strings.Contains(strings.ToLower(prov.Name), query) {
lock.Lock()
results = append(results, &SearchResult{
Name: prov.Name,
Type: "Package",
URL: idx.Name + "/modules/" + strings.Replace(prov.Name, "::", "/", -1),
Obj: prov,
Glyph: "briefcase",
})
lock.Unlock()
}
}
}
}(idx, auth)
}
}(idx)
}
}
wg.Wait()
t := float64(time.Now().UnixNano()-tStart) / 100000 // ms
sort.Sort(ByName(results))
session.Stash["Results"] = results
session.Stash["Duration"] = t
}
session.Stash["Title"] = "SmartPAN"
html, _ := session.RenderTemplate("search.html")
session.Stash["Page"] = "Search"
session.Stash["Content"] = template.HTML(html)
session.Render("layout.html")
}
示例7: browse
func browse(session *http.Session) {
session.Stash["Title"] = "SmartPAN"
path := ""
repo := ""
itype := ""
fpath := ""
if r, ok := session.Stash["repo"]; ok {
repo = r.(string)
fpath += repo + "/"
found := false
if repo == "SmartPAN" {
found = true
} else {
for fname, _ := range indexes {
if _, ok := indexes[fname][repo]; ok {
found = true
break
}
}
}
if !found {
session.RenderNotFound()
return
}
}
if i, ok := session.Stash["type"]; ok {
itype = i.(string)
fpath += itype + "/"
}
if p, ok := session.Stash["path"]; ok {
path = p.(string)
fpath += path + "/"
}
fpath = strings.TrimSuffix(fpath, "/")
session.Stash["path"] = fpath
bits := strings.Split(path, "/")
fbits := strings.Split(fpath, "/")
dirs := make(map[string]map[string]string, 0)
files := make(map[string]map[string]string, 0)
log.Info("Path: %s, Bits: %d", path, len(bits))
if repo == "" {
dirs = toplevelRepo()
} else if itype == "" {
dirs, files = tlRepo1(repo)
} else {
switch itype {
case "authors":
if len(path) == 0 {
dirs, files = tlRepo2(repo, itype)
} else {
switch len(bits) {
case 1:
log.Info("tlAuthor1")
dirs = tlAuthor1(repo)
case 2:
log.Info("tlAuthor2: %s", bits[1])
dirs = tlAuthor2(repo, bits[1])
case 3:
log.Info("tlAuthor3: %s, %s", bits[1], bits[2])
dirs = tlAuthor3(repo, bits[1], bits[2])
case 4:
log.Info("tlModuleList: %s, %s", repo, bits[1], bits[2], bits[3])
files = tlModuleList(repo, bits[1], bits[2], bits[3])
default:
log.Info("Invalid path - rendering not found")
session.RenderNotFound()
}
}
case "modules":
if path == "" {
dirs, files = tlRepo2(repo, itype)
} else {
if repo == "SmartPAN" {
rbits := bits[1:]
ctx := packages[bits[0]]
log.Info("Starting with context: %s", ctx.Namespace)
for len(rbits) > 0 {
ctx = ctx.Children[rbits[0]]
rbits = rbits[1:]
}
log.Info("Stashing package context: %s", ctx.Namespace)
session.Stash["Package"] = ctx
for ns, _ := range ctx.Children {
files[ns] = map[string]string{
"Name": ns,
"Path": "/" + repo + "/modules/" + path + "/" + ns,
}
}
} else {
rbits := bits[1:]
ctx := idxpackages[repo][bits[0]]
log.Info("Starting with context: %s", ctx.Namespace)
for len(rbits) > 0 {
//.........這裏部分代碼省略.........