-
Notifications
You must be signed in to change notification settings - Fork 3
/
deferwriter.go
41 lines (34 loc) · 962 Bytes
/
deferwriter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* (C)2023 Rayark Inc. - All Rights Reserved
* Rayark Confidential
*
* NOTICE: The intellectual and technical concepts contained herein are
* proprietary to or under control of Rayark Inc. and its affiliates.
* The information herein may be covered by patents, patents in process,
* and are protected by trade secret or copyright law.
* You may not disseminate this information or reproduce this material
* unless otherwise prior agreed by Rayark Inc. in writing.
*/
package middleware
import (
"bytes"
"net/http"
)
type DeferWriter struct {
http.ResponseWriter
buf *bytes.Buffer
}
func NewDeferWriter(w http.ResponseWriter) *DeferWriter {
return &DeferWriter{
ResponseWriter: w,
buf: new(bytes.Buffer),
}
}
func (w *DeferWriter) Bytes() []byte {
return w.buf.Bytes()
}
func (w *DeferWriter) Write(b []byte) (int, error) {
return w.buf.Write(b)
}
func (w *DeferWriter) WriteAll() {
w.ResponseWriter.Write(w.buf.Bytes())
}