本文整理汇总了Golang中html/template.URL函数的典型用法代码示例。如果您正苦于以下问题:Golang URL函数的具体用法?Golang URL怎么用?Golang URL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了URL函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ReverseUrl
// Return a url capable of invoking a given controller method:
// "Application.ShowApp 123" => "/app/123"
func ReverseUrl(args ...interface{}) (template.URL, error) {
if len(args) == 0 {
return "", fmt.Errorf("no arguments provided to reverse route")
}
action := args[0].(string)
if action == "Root" {
return template.URL(AppRoot), nil
}
actionSplit := strings.Split(action, ".")
if len(actionSplit) != 2 {
return "", fmt.Errorf("reversing '%s', expected 'Controller.Action'", action)
}
// Look up the types.
var c Controller
if err := c.SetAction(actionSplit[0], actionSplit[1]); err != nil {
return "", fmt.Errorf("reversing %s: %s", action, err)
}
// Unbind the arguments.
argsByName := make(map[string]string)
for i, argValue := range args[1:] {
Unbind(argsByName, c.MethodType.Args[i].Name, argValue)
}
return template.URL(MainRouter.Reverse(args[0].(string), argsByName).Url), nil
}
开发者ID:ericcapricorn,项目名称:revel,代码行数:30,代码来源:template.go
示例2: subjectGroupPage
func subjectGroupPage(e env.Env, w http.ResponseWriter, r *http.Request) {
if redir := checkRedirect(e, w, r, 2); redir {
return
}
header(e, w, r, 2)
defer footer(e, w, r)
path := strings.Split(r.URL.Path, "/")
subjID, err := strconv.Atoi(path[3])
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
subj := e.Subjects[subjID]
f := getFilter(e, r)
g, err := e.GroupByFilteredClass(path[3], "", f)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
classes, err := e.Classes(path[3], f.Date)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
}
sort.Sort(sort.StringSlice(classes))
clsGrps := []subGroup{}
for _, c := range classes {
grp := g.SubGroup(group.Class(subj.Subj, c))
if len(grp.Students) > 0 {
clsGrps = append(clsGrps, subGroup{c, template.URL(c), grp})
}
}
data := struct {
Query template.URL
Year string
Subj *subject.Subject
SubGroups []subGroup
Matrix subGroupMatrix
Classes []subGroup
}{
template.URL(r.URL.RawQuery),
f.Year,
subj,
subGroups(g),
groupMatrix(g),
clsGrps,
}
err = e.Templates.ExecuteTemplate(w, "subjectgroups.tmpl", data)
if err != nil {
fmt.Fprintf(w, "Error: %v", err)
return
}
}
开发者ID:andrewcharlton,项目名称:school-dashboard,代码行数:59,代码来源:subjectgroups.go
示例3: staticFileFn
func staticFileFn(p string) htemp.URL {
h, err := fileHashFn("static/" + p)
if err != nil {
log.Printf("WARNING could not read static file %s, %v", p, err)
return htemp.URL("/-/static/" + p)
}
return htemp.URL("/-/static/" + p + "?v=" + h)
}
开发者ID:jmcvetta,项目名称:gddo,代码行数:8,代码来源:template.go
示例4: Home
func (p githubPresenter) Home() *template.URL {
switch {
case strings.HasPrefix(p.repo.Root, "github.com/"):
url := template.URL("https://github.com/" + p.ghOwner + "/" + p.ghRepo)
return &url
default:
url := template.URL("http://" + p.repo.Root)
return &url
}
}
开发者ID:pombredanne,项目名称:Go-Package-Store,代码行数:10,代码来源:github.go
示例5: HomePage
func (this gitHubPresenter) HomePage() *template.URL {
switch goPackage := this.repo.GoPackages()[0]; {
case strings.HasPrefix(goPackage.Bpkg.ImportPath, "github.com/"):
url := template.URL("https://github.com/" + this.gitHubOwner + "/" + this.gitHubRepo)
return &url
default:
url := template.URL("http://" + goPackage.Bpkg.ImportPath)
return &url
}
}
开发者ID:leobcn,项目名称:Go-Package-Store,代码行数:10,代码来源:github.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng