-
Notifications
You must be signed in to change notification settings - Fork 87
/
sender.go
46 lines (38 loc) · 947 Bytes
/
sender.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
package main
import (
"log"
"net/http"
"sync"
)
// Sender interface for send requests
type Sender interface {
Send(r *ClickhouseRequest)
SendQuery(r *ClickhouseRequest) (response string, status int, err error)
Len() int64
Empty() bool
WaitFlush() (err error)
}
type fakeSender struct {
sendHistory []string
sendQueryHistory []string
mu sync.Mutex
}
func (s *fakeSender) Send(r *ClickhouseRequest) {
s.mu.Lock()
defer s.mu.Unlock()
s.sendHistory = append(s.sendHistory, r.Params+" "+r.Content)
}
func (s *fakeSender) SendQuery(r *ClickhouseRequest) (response string, status int, err error) {
s.sendQueryHistory = append(s.sendQueryHistory, r.Params+r.Content)
log.Printf("DEBUG: send query: %+v\n", s.sendQueryHistory)
return "", http.StatusOK, nil
}
func (s *fakeSender) Len() int64 {
return 0
}
func (s *fakeSender) Empty() bool {
return true
}
func (s *fakeSender) WaitFlush() error {
return nil
}