-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow.go
52 lines (43 loc) · 807 Bytes
/
flow.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
package main
import (
"bytes"
"io"
"net/http"
"sync"
)
type Flow struct {
ID string
Request http.Request
Response http.Response
}
type Flowsx struct {
Flows map[string]Flow
mutex sync.Mutex
}
func (f *Flowsx) add(flow Flow) {
f.mutex.Lock()
defer f.mutex.Unlock()
f.Flows[flow.ID] = flow
}
func duplicateReadCloser(rc io.ReadCloser) (original io.ReadCloser, duplicated io.ReadCloser) {
var b bytes.Buffer
original = teeReadCloser(rc, &b)
return original, io.NopCloser(&b)
}
func teeReadCloser(rc io.ReadCloser, w io.Writer) Body {
n := io.TeeReader(rc, w)
return Body{
c: rc,
b: n,
}
}
type Body struct {
c io.Closer
b io.Reader
}
func (body Body) Close() error {
return body.c.Close()
}
func (body Body) Read(p []byte) (n int, err error) {
return body.b.Read(p)
}