Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
splichy committed Oct 9, 2020
1 parent 78c3bac commit 5247a54
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
24 changes: 12 additions & 12 deletions clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ type Clickhouse struct {

// ClickhouseRequest - request struct for queue
type ClickhouseRequest struct {
Params string
Query string
Content string
Count int
isInsert bool
Params string
Query string
Content string
Count int
isInsert bool
}

// ErrServerIsDown - signals about server is down
Expand Down Expand Up @@ -180,18 +180,18 @@ func (srv *ClickhouseServer) SendQuery(r *ClickhouseRequest) (response string, s
if r.Params != "" {
url += "?" + r.Params
}
if r.isInsert {
log.Printf("INFO: sending %+v rows to %+v of %+v\n", r.Count, srv.URL, r.Query)
}
if r.isInsert {
log.Printf("INFO: sending %+v rows to %+v of %+v\n", r.Count, srv.URL, r.Query)
}
resp, err := srv.Client.Post(url, "", strings.NewReader(r.Content))
if err != nil {
srv.Bad = true
return err.Error(), http.StatusBadGateway, ErrServerIsDown
} else {
if r.isInsert {
log.Printf("INFO: sent %+v rows to %+v of %+v\n", r.Count, srv.URL, r.Query)
}
}
if r.isInsert {
log.Printf("INFO: sent %+v rows to %+v of %+v\n", r.Count, srv.URL, r.Query)
}
}
buf, _ := ioutil.ReadAll(resp.Body)
s := string(buf)
if resp.StatusCode >= 502 {
Expand Down
20 changes: 10 additions & 10 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (t *Table) Content() string {
// Flush - sends collected data in table to clickhouse
func (t *Table) Flush() {
req := ClickhouseRequest{
Params: t.Params,
Query: t.Query,
Content: t.Content(),
Count: len(t.Rows),
isInsert: true,
Params: t.Params,
Query: t.Query,
Content: t.Content(),
Count: len(t.Rows),
isInsert: true,
}
t.Sender.Send(&req)
t.Rows = make([]string, 0, t.FlushCount)
Expand Down Expand Up @@ -120,11 +120,11 @@ func (t *Table) Add(text string) {
t.mu.Lock()
defer t.mu.Unlock()
t.count++
if t.Format != "RowBinary" {
t.Rows = append(t.Rows, strings.Split(text, "\n")...)
} else {
t.Rows = append(t.Rows, text)
}
if t.Format != "RowBinary" {
t.Rows = append(t.Rows, strings.Split(text, "\n")...)
} else {
t.Rows = append(t.Rows, text)
}
if len(t.Rows) >= t.FlushCount {
t.Flush()
}
Expand Down
6 changes: 3 additions & 3 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ func (d *FileDumper) ProcessNextDump(sender Sender) error {
}
if data != "" {
params := ""
query := ""
query := ""
lines := strings.Split(data, "\n")
if !HasPrefix(lines[0], "insert") {
params = lines[0]
query = lines[1]
query = lines[1]
data = strings.Join(lines[1:], "\n")
}
_, status, err := sender.SendQuery(&ClickhouseRequest{Params: params, Content: data, Query: query, Count: len(lines[2:]), isInsert: true})
_, status, err := sender.SendQuery(&ClickhouseRequest{Params: params, Content: data, Query: query, Count: len(lines[2:]), isInsert: true})
if err != nil {
return fmt.Errorf("server error (%+v) %+v", status, err)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var date = "unknown"
func main() {

log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.SetFlags(log.LstdFlags | log.Lmicroseconds)

configFile := flag.String("config", "config.json", "config file (json)")

Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (server *Server) writeHandler(c echo.Context) error {
go server.Collector.Push(params, content)
return c.String(http.StatusOK, "")
}
resp, status, _ := server.Collector.Sender.SendQuery(&ClickhouseRequest{Params: qs, Content: s, isInsert: false})
resp, status, _ := server.Collector.Sender.SendQuery(&ClickhouseRequest{Params: qs, Content: s, isInsert: false})
return c.String(status, resp)
}

Expand Down

0 comments on commit 5247a54

Please sign in to comment.