-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
70 lines (57 loc) · 1.17 KB
/
response.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package robfigcron
import (
"net/http"
"github.com/zhiyunliu/glue/contrib/alloter"
"github.com/zhiyunliu/golibs/xtypes"
)
var _ alloter.ResponseWriter = (*Response)(nil)
const (
noWritten = -1
defaultStatus = http.StatusOK
)
// Request 处理任务请求
type Response struct {
status int
size int
header xtypes.SMap
//stream *bufio.Writer
}
// newResponse 构建任务请求
func newResponse() (r *Response) {
r = &Response{
header: make(xtypes.SMap),
size: noWritten,
status: defaultStatus,
}
return r
}
func (r *Response) Status() int {
return r.status
}
func (r *Response) Size() int {
return r.size
}
// Returns true if the response body was already written.
func (r *Response) Written() bool {
return r.size != noWritten
}
func (r *Response) WriteHeader(code int) {
if code > 0 && r.status != code {
r.status = code
}
}
func (r *Response) Header() xtypes.SMap {
return r.header
}
func (r *Response) Write(data []byte) (n int, err error) {
r.size += len(data)
return
}
// Writes the string into the response body.
func (r *Response) WriteString(s string) (n int, err error) {
r.size += n
return
}
func (r *Response) Flush() error {
return nil
}