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


Golang Context.URL方法代碼示例

本文整理匯總了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
//.........這裏部分代碼省略.........
開發者ID:zaolab,項目名稱:sunnified,代碼行數:101,代碼來源:viewfunc.go


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