esway/internal/model/writer.go

35 lines
618 B
Go
Raw Permalink Normal View History

2024-12-19 15:03:36 +08:00
package model
import (
"bytes"
"io"
"github.com/loveuer/nf"
)
type CopyResponseWriter struct {
nf.ResponseWriter
buf *bytes.Buffer
}
func (w CopyResponseWriter) Write(b []byte) (int, error) {
w.buf.Write(b)
return w.ResponseWriter.Write(b)
}
func (w CopyResponseWriter) String() string {
return w.buf.String()
}
func (w CopyResponseWriter) Bytes() []byte {
return w.buf.Bytes()
}
func (w CopyResponseWriter) Reader() io.Reader {
return w.buf
}
func NewCopyWriter(w nf.ResponseWriter) *CopyResponseWriter {
return &CopyResponseWriter{buf: bytes.NewBuffer(make([]byte, 0, 1024)), ResponseWriter: w}
}