当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Event方法代码示例

本文整理汇总了Golang中github.com/zaolab/sunnified/web.Context.Event方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Event方法的具体用法?Golang Context.Event怎么用?Golang Context.Event使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/zaolab/sunnified/web.Context的用法示例。


在下文中一共展示了Context.Event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ServeRequestedEndPoint

func (this *SunnyApp) ServeRequestedEndPoint(w http.ResponseWriter, r *http.Request, rep *router.RequestedEndPoint) {
	atomic.AddInt32(&this.runners, 1)
	defer this.decrunners()

	if atomic.LoadInt32(&this.closed) == 1 || w == nil || r == nil {
		return
	}

	sw := &SunnyResponseWriter{
		Status:         200,
		ResponseWriter: w,
		midwares:       nil,
	}
	w = sw

	var sunctxt *web.Context

	if rep == nil {
		goto notfound
	}

	defer func() {
		if err := recover(); err != nil {
			if re, ok := err.(web.Redirection); ok {
				this.triggerevent(sunctxt, "redirect", map[string]interface{}{"redirection": re})
			} else if e, ok := err.(web.ContextError); ok {
				this.triggerevent(sunctxt, "contexterror", map[string]interface{}{"context.error": e})
				handler.ErrorHtml(w, r, e.Code())
			} else {
				log.Println(err)
				this.triggererror(sunctxt, err)
			}
		}

		if sunctxt != nil {
			log.Println(fmt.Sprintf("ip: %s; r: %s %s; d: %s; %d",
				sunctxt.RemoteAddress().String(), r.Method, r.URL.Path, time.Since(sunctxt.StartTime()).String(),
				w.(*SunnyResponseWriter).Status))
			sunctxt.Close()
		}
		if r.MultipartForm != nil {
			r.MultipartForm.RemoveAll()
		}
	}()

	sunctxt = web.NewSunnyContext(w, r, this.id)
	sunctxt.Event = this.ev.NewSubRouter(event.M{"sunny.context": sunctxt})
	sunctxt.UPath = rep.UPath
	sunctxt.PData = rep.PData
	sunctxt.Ext = rep.Ext
	sunctxt.MaxFileSize = this.MaxFileSize
	sunctxt.ParseRequestData()
	sw.ctxt = sunctxt

	for n, f := range this.resources {
		sunctxt.SetResource(n, f())
	}

	for _, midware := range this.MiddleWares {
		midware.Request(sunctxt)
		defer midware.Cleanup(sunctxt)
	}

	if router.HandleHeaders(sunctxt, rep.EndPoint, rep.Handler) {
		return
	}

	sw.midwares = this.mwareresp
	for _, midware := range this.MiddleWares {
		midware.Body(sunctxt)
	}

	if ctrl, ok := rep.Handler.(controller.ControlHandler); ok {
		ctrlmgr := ctrl.GetControlManager(sunctxt)

		if ctrlmgr == nil {
			goto notfound
		}

		sunctxt.Module = ctrlmgr.ModuleName()
		sunctxt.Controller = ctrlmgr.ControllerName()
		sunctxt.Action = ctrlmgr.ActionName()

		if err := sunctxt.WaitRequestData(); err != nil {
			setreqerror(err, w)
			return
		}

		// TODO: Controller should not matter which is called first..
		// make it a goroutine once determined sunctxt and ctrlmgr is completely thread-safe
		for _, midware := range this.MiddleWares {
			midware.Controller(sunctxt, ctrlmgr)
		}

		state, vw := ctrlmgr.PrepareAndExecute()
		defer ctrlmgr.Cleanup()

		if vw != nil && !sunctxt.IsRedirecting() && !sunctxt.HasError() {
			setFuncMap(sunctxt, vw)

//.........这里部分代码省略.........
开发者ID:zaolab,项目名称:sunnified,代码行数:101,代码来源:sunny.go


注:本文中的github.com/zaolab/sunnified/web.Context.Event方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。