Skip to content

Commit

Permalink
feat: add more DQL API feautures, add lint/Makefile (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
coanor committed Apr 14, 2023
1 parent bf62d7d commit 1a45b47
Show file tree
Hide file tree
Showing 14 changed files with 1,033 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lint.err
x.json
142 changes: 142 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
[run]
timeout = "10m"
issues-exit-code = 1
skip-files = ["packrd"]
go = "1.18"
skip-dirs = [
# TODO: we should add lint check on the package
]

[linters-settings]

[linters-settings.govet]
check-shadowing = false

[linters-settings.golint]
min-confidence = 0.0

[linters-settings.gocyclo]
min-complexity = 14.0

[linters-settings.gocognit]
min-complexity = 14.0

[linters-settings.cyclo]
min-complexity = 14.0

[linters-settings.maligned]
suggest-new = true

[linters-settings.goconst]
min-len = 3.0
min-occurrences = 4.0

[linters-settings.misspell]
locale = "US"

[linters-settings.funlen]
lines = 230 # default 60
statements = 150 # default 40

[linters-settings.forbidigo]
forbid = ['^print(ln)?$', '^spew\.Print(f|ln)?$', '^spew\.Dump$']

[linters-settings.depguard]
list-type = "blacklist"
include-go-root = false
packages = ["github.com/pkg/errors"]

[linters-settings.godox]
keywords = ["FIXME"]

[linters-settings.wsl]
allow-assign-and-anything = true

[linters-settings.importas]
corev1 = "k8s.io/api/core/v1"
networkingv1beta1 = "k8s.io/api/networking/v1beta1"
extensionsv1beta1 = "k8s.io/api/extensions/v1beta1"
metav1 = "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeerror = "k8s.io/apimachinery/pkg/api/errors"

[linters-settings.gomoddirectives]
replace-allow-list = [
"github.com/abbot/go-http-auth",
"github.com/go-check/check",
"github.com/gorilla/mux",
"github.com/mailgun/minheap",
"github.com/mailgun/multibuf",
]

[linters-settings.lll]
line-length = 150
tab-width = 2

[linters]
enable-all = true
disable = [
# 权且放开他们
"testpackage", # Too strict
"wrapcheck", # 不便于错误处理
"tagliatelle", # 跟现有 json tag 命名方式
"paralleltest", # 可开启,改动范围较大
"noctx", # 要求 HTTP 请求都用 context 形式,改动较大
"nlreturn", # 要求 return 语句前有一个空行
"gomnd", # 不放过任何一个魔术数
"wsl", # 更好代码分段
"prealloc", # Too many false-positive.
"nestif", # Too many false-positive.
"goerr113", # 不能 fmt.Errorf/errors.New
"gochecknoglobals", # 不能搞全局变量
"exhaustivestruct", # 结构体初始化字段是否完整
"golint", # Too strict
"interfacer",
"scopelint", # obsoluted: https://github.com/kyoh86/scopelint#obsoleted


# 代码太复杂
"gocognit",
"gocyclo",

"dupl", # 还不允许有相似代码
#"maligned", # deprecated: https://github.com/mdempsky/maligned

"cyclop",
"gomoddirectives", # used `replace' in go.mod
"nolintlint",
"revive",
"exhaustruct", # [升级 Go1.18 后加入] 要求结构体每次务必每个字段都要填
"varnamelen", # [升级 Go1.18 后加入] 变量名长度检查
"nonamedreturns", # [升级 Go1.18 后加入] 不允许函数有名返回
"forcetypeassert", # [升级 Go1.18 后加入] 强制断言检查
"gci", # [升级 Go1.18 后加入] Tab 键检查
"maintidx", # [升级 Go1.18 后加入] 函数长度检查
"containedctx", # [升级 Go1.18 后加入] Go 不推荐把 context 放在结构体中:https://go.dev/blog/context-and-structs
"ireturn", # [升级 Go1.18 后加入] 函数 interface 返回检查
"contextcheck", # [升级 Go1.18 后加入] 函数参数必须传入 context
"errchkjson", # [升级 Go1.18 后加入] json 序列化/反序列化必须检查
"nilnil", # [升级 Go1.18 后加入] 函数返回 nil, nil 检查
]

[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = []

[[issues.exclude-rules]]
path = "(.+)_test.go"
linters = [
"errcheck",
"goconst",
"funlen",
"godot",
"lll",
"gosec",
"stylecheck",
"wsl",
"unused",
"deadcode",
"unparam",
"maligned",
"varcheck"]
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
lint: lint_deps
golangci-lint run --fix | tee lint.err # https://golangci-lint.run/usage/install/#local-installation

lint_deps: gofmt vet

vet:
@go vet ./...

gofmt:
@GO111MODULE=off gofmt -l $(shell find . -type f -name '*.go'| grep -v "/vendor/\|/.git/")

copyright_check:
@python3 copyright.py --dry-run && \
{ echo "copyright check ok"; exit 0; } || \
{ echo "copyright check failed"; exit -1; }

copyright_check_auto_fix:
@python3 copyright.py --fix
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# DQL Golang SDK

English | [简体中文](README_cn.md)

<h1 align="center">DQL Go SDK</h1>

[![GoDoc](https://godoc.org/github.com/GuanceCloud/dql-go?status.svg)](https://godoc.org/github.com/GuanceCloud/dql-go)
Expand All @@ -23,4 +21,4 @@ import _ "github.com/GuanceCloud/dql-go"

## Examples

See simple examples under *examples* path.
See simple examples under *examples* directory or find examples in *query_test.go*.
26 changes: 0 additions & 26 deletions README_cn.md

This file was deleted.

5 changes: 4 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func MustBuildDQL(dql string, opts ...DQLOption) *dql {
// BuildDQL used to build a DQL query with one or more options.
// dqlStr is the basic DQL query string.
func BuildDQL(dqlStr string, opts ...DQLOption) (*dql, error) {
q := &dql{DQL: dqlStr}
q := &dql{
DQL: dqlStr,
SearchAfter: []any{}, // default enable search-after
}

for _, opt := range opts {
if opt != nil {
Expand Down
Loading

0 comments on commit 1a45b47

Please sign in to comment.