本文整理汇总了Golang中github.com/zaolab/sunnified/web.Context.URL方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.URL方法的具体用法?Golang Context.URL怎么用?Golang Context.URL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zaolab/sunnified/web.Context
的用法示例。
在下文中一共展示了Context.URL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setFuncMap
// TODO: refactor this
func setFuncMap(sunctxt *web.Context, vw mvc.View) {
if fview, ok := vw.(mvc.TmplView); ok {
fview.SetViewFunc("URLQ", sunctxt.URL)
fview.SetViewFunc("URL", func(s string) string {
return sunctxt.URL(s)
})
fview.SetViewFunc("Request", func() *http.Request {
return sunctxt.Request
})
fview.SetViewFunc("QueryStr", sunctxt.QueryStr)
fview.SetViewFunc("TimeNow", sunctxt.StartTime)
fview.SetViewFunc("Nl2br", func(s string) template.HTML {
s = strings.Replace(s, "\r\n", "\n", -1)
s = strings.Replace(s, "\r", "\n", -1)
return template.HTML(strings.Replace(template.HTMLEscapeString(s), "\n", "<br>\n", -1))
})
fview.SetViewFunc("SelectOption", func(selected ...string) template.HTMLAttr {
if len(selected) == 2 && selected[0] == selected[1] {
return " selected "
}
return ""
})
fview.SetViewFunc("SelectMultiOption", func(value []string, selected string) template.HTMLAttr {
if validate.IsIn(selected, value...) {
return " selected "
}
return ""
})
fview.SetViewFunc("CheckOption", func(selected ...string) template.HTMLAttr {
if len(selected) == 2 && selected[0] == selected[1] {
return " checked "
}
return ""
})
fview.SetViewFunc("RawHtml", func(s string) template.HTML {
return template.HTML(s)
})
fview.SetViewFunc("User", func() interface{} {
if sunctxt.Session != nil {
return sunctxt.Session.AuthUser()
}
return nil
})
fview.SetViewFunc("Session", func() web.SessionManager {
if sunctxt.Session != nil {
return sunctxt.Session
}
return nil
})
fview.SetViewFunc("Json", func(i interface{}) template.HTML {
b, _ := json.Marshal(i)
return template.HTML(b)
})
fview.SetViewFunc("Implode", func(join string, slice []string) template.HTML {
buf := bytes.Buffer{}
for _, s := range slice {
buf.WriteString(template.HTMLEscapeString(s))
buf.WriteString(join)
}
if len(slice) > 0 {
buf.Truncate(buf.Len() - len(join))
}
return template.HTML(buf.String())
})
fview.SetViewFunc("Flashes", sunctxt.AllFlashes)
fview.SetViewFunc("CropText", func(s string, l int) string {
if len(s) > l {
s = s[:l-3] + "..."
}
return s
})
fview.SetViewFunc("IRange", func(i ...int) (arr []int) {
count := len(i)
switch count {
case 0:
arr = make([]int, 0)
case 1:
arr = make([]int, i[0]+1)
for k := range arr {
arr[k] = k
}
case 2:
arr = make([]int, int(math.Abs(float64(i[1]-i[0])))+1)
if i[0] > i[1] {
for k := range arr {
arr[k] = i[0]
i[0]--
}
} else {
for k := range arr {
arr[k] = i[0]
i[0]++
}
}
case 3:
if i[0] > i[1] {
i[1] = i[1] - 1
} else {
i[1] = i[1] + 1
//.........这里部分代码省略.........