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


Golang Session.RenderNotFound方法代碼示例

本文整理匯總了Golang中github.com/ian-kent/gotcha/http.Session.RenderNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.RenderNotFound方法的具體用法?Golang Session.RenderNotFound怎麽用?Golang Session.RenderNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ian-kent/gotcha/http.Session的用法示例。


在下文中一共展示了Session.RenderNotFound方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Serve

func (h *Router) Serve(session *http.Session) {
	for _, route := range h.Routes {
		if matches := route.Route.Pattern.FindStringSubmatch(session.Request.URL.Path); len(matches) > 0 {
			_, ok := route.Route.Methods[session.Request.Method]
			if ok {
				for i, named := range route.Route.Pattern.SubexpNames() {
					if len(named) > 0 {
						log.Trace("Matched named pattern '%s': %s", named, matches[i])
						session.Stash[named] = matches[i]
					}
				}
				session.Route = route.Route
				defer func() {
					if e := recover(); e != nil {
						switch e.(type) {
						case string:
							session.RenderException(500, errors.New(e.(string)))
						default:
							session.RenderException(500, e.(error))
						}
						session.Response.Send()
						session.Response.Close()
					}
				}()
				var wg sync.WaitGroup
				wg.Add(1)
				// func() will be executed only if *all* event handlers call next()
				h.Config.Events.Emit(session, events.BeforeHandler, func() {
					route.Handler.ServeHTTP(session)
					h.Config.Events.Emit(session, events.AfterHandler, func() {
						session.Response.Send()
						session.Response.Close()
						wg.Done()
					})
				})
				wg.Wait()
				return
			}
		}
	}

	// no pattern matched; send 404 response
	h.Config.Events.Emit(session, events.BeforeHandler, func() {
		session.RenderNotFound()
		h.Config.Events.Emit(session, events.AfterHandler, func() {
			session.Response.Send()
		})
	})
}
開發者ID:sogko,項目名稱:gotcha,代碼行數:49,代碼來源:router.go


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