Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/run-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Lint

permissions:
contents: read

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: [self-hosted, style-checker-aarch64]
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Install Go
uses: actions/setup-go@v6
Comment thread
alexandear marked this conversation as resolved.
with:
go-version: "1.25"

- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11
111 changes: 44 additions & 67 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,48 @@
version: "2"
run:
tests: false
skip-dirs:
- benchmark
- tests
- internal/cmd

linters-settings:
gocritic:
disabled-checks:
- singleCaseSwitch
- commentFormatting

decorder:
dec-order:
- type
- const
- var
- func
disable-dec-order-check: false

revive:
enable-all-rules: true
rules:
- name: cyclomatic
disabled: true
- name: argument-limit
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
disabled: true
- name: line-length-limit
disabled: true
- name: file-header
disabled: true
- name: cognitive-complexity
disabled: true
- name: banned-characters
disabled: true
- name: max-public-structs
disabled: true
- name: add-constant
disabled: true
- name: unhandled-error
disabled: true
- name: deep-exit
disabled: true
- name: nested-structs
disabled: true

gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'

linters:
disable-all: true
default: none
enable:
- asciicheck
- bodyclose
- gocritic
- govet
- ineffassign
- misspell
- staticcheck
Comment thread
alexandear marked this conversation as resolved.
settings:
gocritic:
disabled-checks:
- commentFormatting
- singleCaseSwitch
exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters: [staticcheck]
path: "lib/cityhash102"
paths:
- benchmark
- examples
- tests
formatters:
enable:
- asciicheck
- bodyclose
- depguard
- gocritic
- gofmt
- govet
- ineffassign
- imports
- misspell
- staticcheck
- gofmt
Comment thread
alexandear marked this conversation as resolved.
- goimports
exclusions:
paths:
- examples
settings:
gofmt:
rewrite-rules:
- pattern: interface{}
replacement: any
- pattern: a[b:len(a)]
replacement: a[b:]
goimports:
local-prefixes:
- "github.com/ClickHouse/clickhouse-go/v2"
5 changes: 3 additions & 2 deletions benchmark/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"crypto/tls"
"encoding/json"
"os"
"testing"

"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
"os"
"testing"
)

const testSet string = "json_bench"
Expand Down
3 changes: 2 additions & 1 deletion benchmark/v2/read-native/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"context"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
"log"
"testing"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
)

func getConnection() clickhouse.Conn {
Expand Down
3 changes: 2 additions & 1 deletion benchmark/v2/write-compress-buffer-limit/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"context"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
"log"
"runtime"
"testing"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
)

func bToMb(b uint64) uint64 {
Expand Down
3 changes: 2 additions & 1 deletion benchmark/v2/write-native/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"context"
"github.com/ClickHouse/clickhouse-go/v2"
"log"
"testing"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
)

func getConnection() clickhouse.Conn {
Expand Down
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func format(tz *time.Location, scale TimeUnit, v any) (string, error) {
}

func join[E any](tz *time.Location, scale TimeUnit, values []E) (string, error) {
items := make([]string, len(values), len(values))
items := make([]string, len(values))
for i := range values {
val, err := format(tz, scale, values[i])
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion clickhouse_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/ClickHouse/ch-go/compress"

"github.com/ClickHouse/clickhouse-go/v2/lib/churl"
)

Expand Down Expand Up @@ -413,7 +414,7 @@ func (o Options) setDefaults() *Options {
if o.MaxCompressionBuffer <= 0 {
o.MaxCompressionBuffer = 10485760
}
if o.Addr == nil || len(o.Addr) == 0 {
if len(o.Addr) == 0 {
switch o.Protocol {
case Native:
o.Addr = []string{"localhost:9000"}
Expand Down
8 changes: 5 additions & 3 deletions clickhouse_rows_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package clickhouse

import (
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
"github.com/stretchr/testify/assert"
"strconv"
"testing"

"github.com/stretchr/testify/assert"

"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

func TestReadWithEmptyBlock(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (o *stdConnOpener) Connect(ctx context.Context) (_ driver.Conn, err error)
}
}

if o.opt.Addr == nil || len(o.opt.Addr) == 0 {
if len(o.opt.Addr) == 0 {
return nil, ErrAcquireConnNoAddress
}

Expand Down
16 changes: 4 additions & 12 deletions client_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,11 @@ func (a ClientInfo) Append(b ClientInfo) ClientInfo {
Comment: make([]string, 0, len(a.Comment)+len(b.Comment)),
}

for _, p := range a.Products {
c.Products = append(c.Products, p)
}
for _, p := range b.Products {
c.Products = append(c.Products, p)
}
c.Products = append(c.Products, a.Products...)
c.Products = append(c.Products, b.Products...)

for _, cm := range a.Comment {
c.Comment = append(c.Comment, cm)
}
for _, cm := range b.Comment {
c.Comment = append(c.Comment, cm)
}
c.Comment = append(c.Comment, a.Comment...)
c.Comment = append(c.Comment, b.Comment...)

return c
}
Expand Down
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"io"
"log/slog"
"net"
"sync"
"syscall"
"time"

"github.com/ClickHouse/clickhouse-go/v2/lib/column"

"github.com/ClickHouse/clickhouse-go/v2/resources"

"github.com/ClickHouse/ch-go/compress"
chproto "github.com/ClickHouse/ch-go/proto"

"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

Expand Down
3 changes: 2 additions & 1 deletion conn_error_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

"github.com/ClickHouse/ch-go/compress"
chproto "github.com/ClickHouse/ch-go/proto"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

// mockNetConn is a mock net.Conn that can be configured to return specific errors
Expand Down
3 changes: 2 additions & 1 deletion conn_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package clickhouse

import (
"context"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
"time"

"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

func (c *connect) exec(ctx context.Context, query string, args ...any) error {
Expand Down
10 changes: 6 additions & 4 deletions conn_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (

"github.com/ClickHouse/ch-go/compress"
chproto "github.com/ClickHouse/ch-go/proto"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
"github.com/andybalholm/brotli"

"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

const (
Expand Down Expand Up @@ -107,7 +108,8 @@ func applyOptionsToRequest(ctx context.Context, req *http.Request, opt *Options)
jwt := queryOpt.jwt
useJWT := jwt != "" || useJWTAuth(opt)

if opt.TLS != nil && useJWT {
switch {
case opt.TLS != nil && useJWT:
if jwt == "" {
var err error
jwt, err = opt.GetJWT(ctx)
Expand All @@ -117,15 +119,15 @@ func applyOptionsToRequest(ctx context.Context, req *http.Request, opt *Options)
}

req.Header.Set("Authorization", "Bearer "+jwt)
} else if opt.TLS != nil && len(opt.Auth.Username) > 0 {
case opt.TLS != nil && len(opt.Auth.Username) > 0:
req.Header.Set("X-ClickHouse-User", opt.Auth.Username)
if len(opt.Auth.Password) > 0 {
req.Header.Set("X-ClickHouse-Key", opt.Auth.Password)
req.Header.Set("X-ClickHouse-SSL-Certificate-Auth", "off")
} else {
req.Header.Set("X-ClickHouse-SSL-Certificate-Auth", "on")
}
} else if opt.TLS == nil && len(opt.Auth.Username) > 0 {
case opt.TLS == nil && len(opt.Auth.Username) > 0:
if len(opt.Auth.Password) > 0 {
req.URL.User = url.UserPassword(opt.Auth.Username, opt.Auth.Password)

Expand Down
2 changes: 1 addition & 1 deletion conn_http_async_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (h *httpConnect) asyncInsert(ctx context.Context, query string, wait bool,
}
}

res, err := h.sendQuery(ctx, query, &options, nil)
res, err := h.sendQuery(ctx, query, &options, nil) //nolint:bodyclose // false positive
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions conn_http_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package clickhouse
import (
"context"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
"io"
"log/slog"
"os"
"slices"

"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
)

func fetchColumnNamesAndTypesForInsert(h *httpConnect, release nativeTransportRelease, ctx context.Context, tableName string, requestedColumnNames []string) ([]ColumnNameAndType, error) {
Expand Down Expand Up @@ -267,7 +268,7 @@ func (b *httpBatch) Send() (err error) {
b.conn.logger.Debug("batch: sending via HTTP",
slog.Int("columns", len(b.block.Columns)),
slog.Int("rows", b.block.Rows()))
res, err := b.conn.sendStreamQuery(b.ctx, pipeReader, &options, headers)
res, err := b.conn.sendStreamQuery(b.ctx, pipeReader, &options, headers) //nolint:bodyclose // false positive
if err != nil {
return fmt.Errorf("batch sendStreamQuery: %w", err)
}
Expand Down
Loading
Loading