Skip to content

Commit

Permalink
Merge 2804cea into d58d64e
Browse files Browse the repository at this point in the history
  • Loading branch information
gabolaev committed Nov 18, 2018
2 parents d58d64e + 2804cea commit 96a7971
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea/
_vendor/
vendor/
coverage.out
Gopkg.lock
14 changes: 5 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ services:

before_install:
- travis_retry docker pull yandex/clickhouse-server
- docker run -d -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server yandex/clickhouse-server
- make up_docker_server
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

install:
- travis_retry go get -u github.com/golang/lint/golint
- travis_retry go get github.com/mattn/goveralls
- travis_retry go get golang.org/x/tools/cmd/cover
- travis_retry go get github.com/stretchr/testify
- make init
- travis_retry go get -v github.com/mattn/goveralls/...

before_script:
- export TEST_CLICKHOUSE_DSN="http://localhost:8123/default"

script:
- test -z "$(golint ./... | tee /dev/stderr)"
- go vet ./...
- test -z "$(gofmt -d -s . | tee /dev/stderr)"
- go test -v -covermode=count -coverprofile=coverage.out .
- make test
- goveralls -coverprofile=coverage.out -service=travis-ci
14 changes: 14 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# for tests
required = ["github.com/golang/lint/golint"]

[[override]]
name = "golang.org/x/tools"
revision = "a019f6b7c5bfcffdf421924fc0ddb74b867a53f2"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.2"

[prune]
go-tests = true
unused-packages = true
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SHELL := /bin/bash

init:
dep ensure -v
go install ./vendor/...

up_docker_server: stop_docker_server
docker run --rm=true -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server -d yandex/clickhouse-server;

stop_docker_server:
test -n "$$(docker ps --format {{.Names}} | grep dbr-clickhouse-server)" && docker stop dbr-clickhouse-server || true

test: up_docker_server
test -z "$$(golint ./... | grep -v vendor | tee /dev/stderr)"
go vet -v ./...
test -z "$$(gofmt -d -s $$(find . -name \*.go -print | grep -v vendor) | tee /dev/stderr)"
go test -v -covermode=count -coverprofile=coverage.out .
$(MAKE) stop_docker_server
53 changes: 48 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ func main() {
if err != nil {
log.Fatal(err)
}
stmt, err := tx.Prepare("INSERT INTO example (country_code, os_id, browser_id, categories, action_day, action_time) VALUES (?, ?, ?, ?, ?, ?)")
stmt, err := tx.Prepare(`
INSERT INTO example (
country_code,
os_id,
browser_id,
categories,
action_day,
action_time
) VALUES (
?, ?, ?, ?, ?, ?
)`)

if err != nil {
log.Fatal(err)
}
Expand All @@ -108,7 +119,17 @@ func main() {
log.Fatal(err)
}

rows, err := connect.Query("SELECT country_code, os_id, browser_id, categories, action_day, action_time FROM example")
rows, err := connect.Query(`
SELECT
country_code,
os_id,
browser_id,
categories,
action_day,
action_time
FROM
example`)

if err != nil {
log.Fatal(err)
}
Expand All @@ -120,10 +141,19 @@ func main() {
categories []int16
actionDay, actionTime time.Time
)
if err := rows.Scan(&country, &os, &browser, &categories, &actionDay, &actionTime); err != nil {
if err := rows.Scan(
&country,
&os,
&browser,
&categories,
&actionDay,
&actionTime,
); err != nil {
log.Fatal(err)
}
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_day: %s, action_time: %s", country, os, browser, categories, actionDay, actionTime)
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_day: %s, action_time: %s",
country, os, browser, categories, actionDay, actionTime,
)
}
}
```
Expand Down Expand Up @@ -161,10 +191,23 @@ func main() {
}

for _, item := range items {
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_time: %s", item.CountryCode, item.OsID, item.BrowserID, item.Categories, item.ActionTime)
log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_time: %s",
item.CountryCode, item.OsID, item.BrowserID, item.Categories, item.ActionTime,
)
}
}
```

## Go versions
Officially support last 3 golang releases


## Development:
You can check the effect of changes on Travis CI or run tests locally:

``` bash
make init # dep ensure and install
make test
```

_Remember that `init` will add a few binaries used for testing (like `golint`) into your GOPATH_
3 changes: 1 addition & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func ParseDSN(dsn string) (*Config, error) {
}
cfg := NewConfig()

cfg.Scheme = u.Scheme
cfg.Host = u.Host
cfg.Scheme, cfg.Host = u.Scheme, u.Host
if len(u.Path) > 1 {
// skip '/'
cfg.Database = u.Path[1:]
Expand Down
5 changes: 2 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func readResponse(response *http.Response) (result []byte, err error) {
}

func numOfColumns(data []byte) int {
cnt := 0
var cnt int
for _, ch := range data {
switch ch {
case '\t':
Expand All @@ -66,8 +66,7 @@ func numOfColumns(data []byte) int {

// splitTSV splits one row of tab separated values, returns begin of next row
func splitTSV(data []byte, out []string) int {
i := 0
k := 0
var i, k int
for j, ch := range data {
switch ch {
case '\t':
Expand Down

0 comments on commit 96a7971

Please sign in to comment.