本文整理汇总了Golang中github.com/goods/httpbuf.Buffer类的典型用法代码示例。如果您正苦于以下问题:Golang Buffer类的具体用法?Golang Buffer怎么用?Golang Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Buffer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ServeHTTP
func (h Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
requestLog.Info("%v %v", r.Method, r.RequestURI)
for _, initializer := range initializers {
initializer(r)
}
buffer := new(httpbuf.Buffer)
err := h(buffer, r)
if err != nil {
fmt.Println(err)
if webErr, ok := err.(WebError); ok {
http.Error(w, webErr.Message, webErr.Code)
} else {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
err = Session(r).Save(r, buffer)
context.Clear(r)
buffer.Apply(w)
}
开发者ID:YouthBuild-USA,项目名称:godata,代码行数:25,代码来源:web.go
示例2: ServeHTTP
// ServeHTTP builds the context and passes onto the real handler
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Create the context
ctx, err := NewContext(req)
if err != nil {
log.LogError("Failed to create context: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer ctx.Close()
// Run the handler, grab the error, and report it
buf := new(httpbuf.Buffer)
log.LogTrace("Web: %v %v %v %v", req.RemoteAddr, req.Proto, req.Method, req.RequestURI)
err = h(buf, req, ctx)
if err != nil {
log.LogError("Error handling %v: %v", req.RequestURI, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Save the session
if err = ctx.Session.Save(req, buf); err != nil {
log.LogError("Failed to save session: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Apply the buffered response to the writer
buf.Apply(w)
}
开发者ID:hotei,项目名称:inbucket,代码行数:31,代码来源:server.go
示例3: ServeHTTP
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, err := models.NewContext(r, store, dbmap, cache)
if err != nil {
fmt.Println("Call to NewContext() returned error.")
log.Println(err)
}
if ctx.User != nil {
activityCache[ctx.User.ID] = time.Now()
fmt.Println("Hashed new user ID in ServeHTTP()")
log.Println(ctx.User.ID)
}
defer ctx.Close()
buffer := new(httpbuf.Buffer)
err = h(buffer, r, ctx)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err = ctx.Session.Save(r, buffer); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
buffer.Apply(w)
}
开发者ID:mdaronco,项目名称:femp_1.1,代码行数:29,代码来源:femp.go
示例4: Buffer
/*
Middleware that buffers all http output. This permits
output to be written before headers are sent. Downside:
no output is sent until it's all ready to be sent, so
this breaks streaming.
Note: currently ignores errors
*/
func Buffer() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
bw := new(httpbuf.Buffer)
next.ServeHTTP(bw, r)
bw.Apply(w)
})
}
}
开发者ID:mvpmvh,项目名称:interpose,代码行数:17,代码来源:buffer.go
示例5: ServeHTTP
func (h LoggedHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if dump, err := httputil.DumpRequest(req, true); err != nil {
logrus.Errorf("Failed to log request:\n%s", err)
} else {
logrus.Info(string(dump))
}
buf := new(httpbuf.Buffer)
h.Handler.ServeHTTP(buf, req)
logrus.Infof("response: %s", buf.String())
buf.Apply(w)
}
开发者ID:drivernation,项目名称:kaiju,代码行数:11,代码来源:handlers.go
示例6: ServeHTTP
func (a WebAction) ServeHTTP(w http.ResponseWriter, r *http.Request) {
buf := new(httpbuf.Buffer)
ctx := &WebContext{
Session: context.Get(r, "session").(*sessions.Session),
User: context.Get(r, "user").(*domain.User),
CSRF: context.Get(r, "csrf").(string),
}
err := a(buf, r, ctx)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
buf.Apply(w)
}
开发者ID:unitrans,项目名称:unitrans,代码行数:15,代码来源:web_legacy.go
示例7: ServeHTTP
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
//create the context
ctx, err := NewContext(req)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
//run the handler and grab the error, and report it
buf := new(httpbuf.Buffer)
err = h(buf, req, ctx)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
//save the session
if err = ctx.Session.Save(req, buf); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
//apply the buffered response to the writer
buf.Apply(w)
}
开发者ID:samlecuyer,项目名称:lomap,代码行数:19,代码来源:handlers.go
示例8: ServeHTTP
// ServeHTTP mandatory middleware part
func (a *Session) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
session, err := a.session.Get(r, "_session")
if err != nil {
http.SetCookie(rw, &http.Cookie{Name: "_session", Expires: time.Now().Add(-1 * time.Hour)})
http.Error(rw, err.Error(), http.StatusBadRequest)
return
}
log.Print("zero ", session.Values)
session.Values["time"] = time.Now().String()
context.Set(r, "session", session)
buf := new(httpbuf.Buffer)
next(buf, r)
session.Save(r, rw)
buf.Apply(rw)
// res := rw.(ResponseWriter)
}
开发者ID:unitrans,项目名称:unitrans,代码行数:22,代码来源:webAuth.go
示例9: ServeHTTP
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Expires", "Fri, 02 Oct 1998 20:00:00 GMT")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Cache-Control", "no-store, no-cache, max-age=0, must-revalidate")
ctx, err := NewContext(req)
if err != nil {
raven.CaptureError(err, nil)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer ctx.Close()
//run the handler and grab the error, and report it
buf := new(httpbuf.Buffer)
err = h(buf, req, ctx)
if err != nil {
raven.CaptureError(err, nil)
log.Printf("call handler error: %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
ctx.afterHandle()
//save the session
if len(ctx.Session.Values) > 0 { // session not empty only
if err = ctx.Session.Save(req, buf); err != nil {
log.Printf("session.save error: %s", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
//apply the buffered response to the writer
buf.Apply(w)
}
开发者ID:gooops,项目名称:staffio,代码行数:37,代码来源:handlers.go
注:本文中的github.com/goods/httpbuf.Buffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论