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


Golang WriterProxy.WriteHeader方法代码示例

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


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

示例1: bless

// bless is the meat of kami.
// It wraps a ContextHandler into an httprouter compatible request,
// in order to run all the middleware and other special handlers.
func bless(k ContextHandler, base *context.Context, m *middlewares, panicHandler *HandlerType, logHandler *func(context.Context, mutil.WriterProxy, *http.Request), closeHandler *func(context.Context, *http.Request)) httprouter.Handle {
	return func(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
		ctx := defaultContext(*base, r)
		if len(params) > 0 {
			ctx = newContextWithParams(ctx, params)
		}
		ranLogHandler := false   // track this in case the log handler blows up
		ranCloseHandler := false // track this in case the log handler blows up

		writer := w
		var proxy mutil.WriterProxy
		if *logHandler != nil {
			proxy = mutil.WrapWriter(w)
			writer = proxy
		}

		if *panicHandler != nil {
			defer func() {
				if err := recover(); err != nil {
					ctx = newContextWithException(ctx, err)
					wrap(*panicHandler).ServeHTTPContext(ctx, writer, r)

					if *closeHandler != nil && !ranCloseHandler {
						(*closeHandler)(ctx, r)
					}

					if *logHandler != nil && !ranLogHandler {
						(*logHandler)(ctx, proxy, r)
						// should only happen if header hasn't been written
						proxy.WriteHeader(http.StatusInternalServerError)
					}

				}
			}()
		}

		ctx, ok := m.run(ctx, writer, r)
		if ok {
			k.ServeHTTPContext(ctx, writer, r)
		}

		if *closeHandler != nil {
			ranCloseHandler = true
			(*closeHandler)(ctx, r)
		}

		if *logHandler != nil {
			ranLogHandler = true
			(*logHandler)(ctx, proxy, r)
			// should only happen if header hasn't been written
			proxy.WriteHeader(http.StatusInternalServerError)
		}
	}
}
开发者ID:SLASH2NL,项目名称:kami,代码行数:57,代码来源:kami.go

示例2: bless

// bless is the meat of kami.
// It wraps a HandleFn into an httprouter compatible request,
// in order to run all the middleware and other special handlers.
func bless(k ContextHandler) httprouter.Handle {
	return func(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
		ctx := Context
		if len(params) > 0 {
			ctx = newContextWithParams(Context, params)
		}
		ranLogHandler := false // track this in case the log handler blows up

		writer := w
		var proxy mutil.WriterProxy
		if LogHandler != nil {
			proxy = mutil.WrapWriter(w)
			writer = proxy
		}

		if PanicHandler != nil {
			defer func() {
				if err := recover(); err != nil {
					ctx = newContextWithException(ctx, err)
					wrap(PanicHandler).ServeHTTPContext(ctx, writer, r)

					if LogHandler != nil && !ranLogHandler {
						LogHandler(ctx, proxy, r)
						// should only happen if header hasn't been written
						proxy.WriteHeader(500)
					}
				}
			}()
		}

		ctx, ok := run(ctx, writer, r)
		if ok {
			k.ServeHTTPContext(ctx, writer, r)
		}

		if LogHandler != nil {
			ranLogHandler = true
			LogHandler(ctx, proxy, r)
			// should only happen if header hasn't been written
			proxy.WriteHeader(500)
		}
	}
}
开发者ID:gunosy,项目名称:kami,代码行数:46,代码来源:kami.go


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