File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 1
1
dependency :
2
2
go get -u github.com/golang/dep/cmd/dep
3
- dep ensure -update
3
+ dep ensure
4
4
5
5
test :
6
6
echo " " > coverage.txt
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package labstack
2
2
3
3
import (
4
4
"sync"
5
- "time"
6
5
7
6
"github.com/dghubble/sling"
8
7
glog "github.com/labstack/gommon/log"
@@ -54,12 +53,6 @@ func (c *Client) Cube() (cube *Cube) {
54
53
DispatchInterval : 60 ,
55
54
}
56
55
cube .resetRequests ()
57
- go func () {
58
- d := time .Duration (cube .DispatchInterval ) * time .Second
59
- for range time .Tick (d ) {
60
- cube .dispatch ()
61
- }
62
- }()
63
56
return
64
57
}
65
58
Original file line number Diff line number Diff line change 19
19
sling * sling.Sling
20
20
requests []* CubeRequest
21
21
activeRequests int64
22
+ started int64
22
23
mutex * sync.RWMutex
23
24
logger * log.Logger
24
25
@@ -119,6 +120,16 @@ func (c *Cube) dispatch() error {
119
120
120
121
// Start starts recording an HTTP request.
121
122
func (c * Cube ) Start (r * http.Request , w http.ResponseWriter ) (request * CubeRequest ) {
123
+ if c .started == 0 {
124
+ go func () {
125
+ d := time .Duration (c .DispatchInterval ) * time .Second
126
+ for range time .Tick (d ) {
127
+ c .dispatch ()
128
+ }
129
+ }()
130
+ atomic .AddInt64 (& c .started , 1 )
131
+ }
132
+
122
133
request = & CubeRequest {
123
134
ID : RequestID (r , w ),
124
135
Time : time .Now (),
You can’t perform that action at this time.
0 commit comments