Skip to content
Closed
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
32 changes: 32 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and test

on:
push:
tags:
- 'v*'
- 'build*'
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:

test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Unit tests
run: |
go mod tidy
go test ./... -v
31 changes: 27 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
name: CI
name: Linting checks

on:
push:
tags:
- 'v*'
- 'build*'
- 'lint*'
branches:
- main
- develop
pull_request:
branches:
- main
- develop

env:
GOLANGCI_LINT_VERSION: ${{ vars.GOLANGCI_LINT_VERSION == '' && 'v2.5.0' || vars.GOLANGCI_LINT_VERSION }}
DEFAULT_STEP_TIMEOUT: ${{ vars.DEFAULT_STEP_TIMEOUT_MIN == '' && '20' || vars.DEFAULT_STEP_TIMEOUT_MIN }}

jobs:

lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -16,16 +32,23 @@ jobs:
go-version: 1.17

- name: Restore bin
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./bin
key: ${{ runner.os }}-bin-${{ hashFiles('**/go.sum') }}

- name: Linting
run: make lint
run: |
make lint GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} | tee lint.log 2>&1 || true

- name: Upload linting results
uses: actions/upload-artifact@v4
with:
name: lint-results
path: lint.log

- name: Cache bin
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./bin
key: ${{ runner.os }}-bin-${{ hashFiles('**/go.sum') }}
178 changes: 178 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
version: "2"
output:
formats:
text:
path: stdout
linters:
default: none
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- cyclop
- dupl
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
- forbidigo
- funlen
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
# - goconst
- gocritic
- gocyclo
- godot
- gomodguard
- goprintffuncname
- gosec
- govet
- ineffassign
- lll
- loggercheck
- makezero
- mnd
- musttag
- nakedret
- nestif
- nilerr
- nilnil
# - noctx
# - nolintlint
- nonamedreturns
- nosprintfhostport
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
# - staticcheck
- testableexamples
- testpackage
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
settings:
cyclop:
max-complexity: 30
package-average: 10
errcheck:
check-type-assertions: true
exhaustive:
check:
- switch
- map
exhaustruct:
exclude:
- ^net/http.Client$
- ^net/http.Cookie$
- ^net/http.Request$
- ^net/http.Response$
- ^net/http.Server$
- ^net/http.Transport$
- ^net/url.URL$
- ^os/exec.Cmd$
- ^reflect.StructField$
- ^github.com/Shopify/sarama.Config$
- ^github.com/Shopify/sarama.ProducerMessage$
- ^github.com/mitchellh/mapstructure.DecoderConfig$
- ^github.com/prometheus/client_golang/.+Opts$
- ^github.com/spf13/cobra.Command$
- ^github.com/spf13/cobra.CompletionOptions$
- ^github.com/stretchr/testify/mock.Mock$
- ^github.com/testcontainers/testcontainers-go.+Request$
- ^github.com/testcontainers/testcontainers-go.FromDockerfile$
- ^golang.org/x/tools/go/analysis.Analyzer$
- ^google.golang.org/protobuf/.+Options$
- ^gopkg.in/yaml.v3.Node$
funlen:
lines: 100
statements: 50
gocognit:
min-complexity: 20
gocritic:
settings:
captLocal:
paramsOnly: false
underef:
skipRecvDeref: false
gomodguard:
blocked:
modules:
- github.com/golang/protobuf:
recommendations:
- google.golang.org/protobuf
reason: see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules
- github.com/satori/go.uuid:
recommendations:
- github.com/google/uuid
reason: satori's package is not maintained
- github.com/gofrs/uuid:
recommendations:
- github.com/google/uuid
reason: gofrs' package is not go module
govet:
disable:
- fieldalignment
enable-all: true
settings:
shadow:
strict: true
mnd:
ignored-functions:
- os.Chmod
- os.Mkdir
- os.MkdirAll
- os.OpenFile
- os.WriteFile
- prometheus.ExponentialBuckets
- prometheus.ExponentialBucketsRange
- prometheus.LinearBuckets
nakedret:
max-func-lines: 0
nolintlint:
require-explanation: true
require-specific: true
allow-no-explanation:
- funlen
- gocognit
- lll
rowserrcheck:
packages:
- github.com/jmoiron/sqlx
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- stylecheck
path: command\.go
paths:
- third_party$
- '.*_test\.go$'
- builtin$
- examples$
issues:
max-same-issues: 50
formatters:
enable:
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ GOPATH = $(HOME)/go
GOBIN = $(GOPATH)/bin
GO ?= GOGC=off $(shell which go)

GOLANGCI_LINT_VERSION = v2.5.0

# Printing
V = 0
Q = $(if $(filter 1,$V),,@)
Expand All @@ -23,7 +25,7 @@ $(BIN)/%: | $(BIN) ; $(info $(M) building $(@F)…)

GOLANGCI_LINT = $(BIN)/golangci-lint
$(BIN)/golangci-lint: | $(BIN) ;
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.42.1
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh| sh -s $(GOLANGCI_LINT_VERSION)

STRINGER = $(BIN)/stringer
GOIMPORTS = $(BIN)/goimports
Expand Down
8 changes: 4 additions & 4 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@

func (srv *Server) handleSimpleQuery(ctx context.Context, cn SQLConnection) error {
if srv.SimpleQuery == nil && srv.SQLBackendFactory == nil {
ErrorCode(cn, NewErrUnimplementedMessageType(types.ClientSimpleQuery))

Check failure on line 197 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)

Check failure on line 197 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)
return readyForQuery(cn, types.ServerIdle)
}

Expand All @@ -214,14 +214,14 @@
if q == "" {
if i == len(qArr)-1 {
// trailing semicolon, ignore
commandComplete(cn, "OK")

Check failure on line 217 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)

Check failure on line 217 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)
return readyForQuery(cn, types.ServerIdle)
}
continue
}
rdr, err := cn.HandleSimpleQuery(ctx, q)
if err != nil {
ErrorCode(cn, err)

Check failure on line 224 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)

Check failure on line 224 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)
return readyForQuery(cn, types.ServerIdle)
}
dw := &dataWriter{
Expand All @@ -231,7 +231,7 @@
var headersWritten bool
for {
if rdr == nil {
dw.Complete("", "OK")

Check failure on line 234 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `dw.Complete` is not checked (errcheck)

Check failure on line 234 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `dw.Complete` is not checked (errcheck)
return readyForQuery(cn, types.ServerIdle)
}
res, err := rdr.Read()
Expand All @@ -239,12 +239,12 @@
if errors.Is(err, io.EOF) {
notices := cn.GetDebugStr()
if res == nil {
dw.Complete(notices, "OK")

Check failure on line 242 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `dw.Complete` is not checked (errcheck)

Check failure on line 242 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `dw.Complete` is not checked (errcheck)
return readyForQuery(cn, types.ServerIdle)
}
if !headersWritten {
headersWritten = true
srv.writeSQLResultHeader(ctx, res, dw)
srv.writeSQLResultHeader(ctx, res, dw, nil)

Check failure on line 247 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `srv.writeSQLResultHeader` is not checked (errcheck)

Check failure on line 247 in command.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `srv.writeSQLResultHeader` is not checked (errcheck)
}
srv.writeSQLResultRows(ctx, res, dw)
// TODO: add debug messages, configurably
Expand Down Expand Up @@ -283,16 +283,16 @@
return nil
}

func (srv *Server) writeSQLResultHeader(ctx context.Context, res sqldata.ISQLResult, writer DataWriter) error {
func (srv *Server) writeSQLResultHeader(ctx context.Context, res sqldata.ISQLResult, writer DataWriter, resultFormats []int16) error {
var colz Columns
for _, c := range res.GetColumns() {
for i, c := range res.GetColumns() {
colz = append(colz,
Column{
Table: c.GetTableId(),
Name: c.GetName(),
Oid: oid.Oid(c.GetObjectID()),
Width: c.GetWidth(),
Format: TextFormat,
Format: resolveResultFormat(resultFormats, i),
},
)
}
Expand Down
8 changes: 8 additions & 0 deletions docs/developer-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Developer Guide

## Running linter locally

```bash
make lint
```
Empty file added docs/postgres_emulation.md
Empty file.
Loading
Loading