Skip to content

Commit

Permalink
improve golangci-lint config (#103)
Browse files Browse the repository at this point in the history
* feat: improve golangci.yml and upgrade package version

* feat: improve golangci-lint config

* fix

* feat: go mod tidy

* modify go version

* Version rollback

* test: modify local regex spread time

* feat: improve code and comment
  • Loading branch information
houseme authored Oct 24, 2022
1 parent 0cadab4 commit a917801
Show file tree
Hide file tree
Showing 44 changed files with 379 additions and 203 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Tencent is pleased to support the open source community by making Polaris available.
#
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

name: golangci-lint
on:
push:
branches:
- main
- release*
- feature/**
pull_request:
branches:
- main
- release*
- feature/**

jobs:
golangci:
strategy:
matrix:
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
43 changes: 43 additions & 0 deletions .github/workflows/revive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Tencent is pleased to support the open source community by making Polaris available.
#
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

name: revive
on:
push:
branches:
- main
- release*
- feature/**
pull_request:
branches:
- main
- release*
- feature/**

jobs:
reviveci:
strategy:
matrix:
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
name: Run Revive Action
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: Run Revive Action
uses: morphy2k/revive-action@v2
with:
# Path to your Revive config within the repo (optional)
config: revive.toml
46 changes: 16 additions & 30 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Tencent is pleased to support the open source community by making Polaris available.
#
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.


name: Go

on:
Expand All @@ -18,36 +34,6 @@ env:
GO111MODULE: on

jobs:

golangci:
strategy:
matrix:
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
Reviveci:
strategy:
matrix:
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
name: Run Revive Action
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: Run Revive Action
uses: morphy2k/revive-action@v2
with:
# Path to your Revive config within the repo (optional)
config: revive.toml

build:
runs-on: ubuntu-latest
# strategy set
Expand Down
93 changes: 84 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
run:
issues-exit-code: 1 #Default
tests: true #Default
skip-dirs: # 设置要忽略的目录
- test
- .*~
- api/swagger/docs
skip-files: # 设置不需要检查的go源码文件,支持正则匹配
- ".*.my.go$"
- ".*.pb.go$"
- _test.go

linters:
# Disable everything by default so upgrades to not include new "default
Expand All @@ -11,16 +19,17 @@ linters:
enable:
# - deadcode
# - errcheck
# - funlen
# - gocritic
# - gofmt
- funlen
- gocritic
- gocyclo
- gofmt
- goimports
# - gosimple
- gosimple
- govet
- godot
# - ineffassign
- misspell
# - revive
- revive
# - staticcheck
# - structcheck
- typecheck
Expand Down Expand Up @@ -76,9 +85,33 @@ linters-settings:
- name: atomic
- name: line-length-limit
severity: error
arguments: [195]
arguments: [180]
- name: unhandled-error
arguments : ["fmt.Printf", "myFunction"]
arguments : ["fmt.Printf", "myFunction", "builder.WriteString","buf.WriteByte","buf.WriteRune","buf.WriteString","buf.WriteTo","buf.Write","fmt.Println","iteratorInstancesProc","buffer.Write","buffer.WriteString","h.Write","fmt.Fprintf","io.WriteString","e.reportAPIStat","f.Close"]
severity: warning
- name: var-naming
severity: warning
disabled: true
arguments:
- [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url","maxQps","ErrorCodeRpcError","ErrorCodeRpcTimeout","Ttl"] # AllowList
- [ "VM" ] # DenyList
- name: string-format
severity: warning
disabled: false
arguments:
- - 'core.WriteError[1].Message'
- '/^([^A-Z]|$)/'
- must not start with a capital letter
- - 'fmt.Errorf[0]'
- '/(^|[^\.!?])$/'
- must not end in punctuation
- - panic
- '/^[^\n]*$/'
- must not contain line breaks
- name: function-result-limit
severity: warning
disabled: false
arguments: [ 4 ]
funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
Expand All @@ -87,8 +120,50 @@ linters-settings:
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
statements: 40
statements: -1
goconst:
# Minimal length of string constant.
# Default: 3
min-len: 2
# Minimum occurrences of constant string count to trigger issue.
# Default: 3
# For subsequent optimization, the value is reduced.
min-occurrences: 3
# Ignore test files.
# Default: false
ignore-tests: true
ignore-tests: true
# Look for existing constants matching the values.
# Default: true
match-constant: false
# Search also for duplicated numbers.
# Default: false
numbers: true
# Minimum value, only works with goconst.numbers
# Default: 3
min: 3
# Maximum value, only works with goconst.numbers
# Default: 3
max: 3
# Ignore when constant is not used as function argument.
# Default: true
ignore-calls: false
gocritic:
disabled-checks:
- ifElseChain
- assignOp
- appendAssign
- singleCaseSwitch
- badCall
- underef
gocyclo:
# Minimal code complexity to report.
# Default: 30 (but we recommend 10-20)
min-complexity: 30
gosimple:
# Select the Go version to target.
# Default: 1.13
# Deprecated: use the global `run.go` instead.
go: "1.15"
# Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: ["all","-S1001","-S1000","-S1025"]
19 changes: 10 additions & 9 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
#### 配置初始化

```go
//使用默认配置对象来初始化配置,连接默认的北极星埋点域名
// 使用默认配置对象来初始化配置,连接默认的北极星埋点域名
cfg := api.NewConfiguration()
```

#### 修改北极星后端集群名

```go
//先初始化配置
// 先初始化配置
cfg := api.NewConfiguration()
//修改发现server集群名
// 修改发现server集群名
cfg.GetGlobal().GetSystem().GetDiscoverCluster().SetService("polaris-server")
//修改心跳server集群名
// 修改心跳server集群名
cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("healthcheck")
//修改监控server集群名
// 修改监控server集群名
cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("polaris.monitor")
```

Expand All @@ -28,7 +28,7 @@ cfg.GetGlobal().GetSystem().GetHealthCheckCluster().SetService("polaris.monitor"

```go
if err := api.SetLoggersDir("/tmp/polaris/log"); err != nil {
//do error handle
// do error handle
}
```

Expand All @@ -38,18 +38,19 @@ if err := api.SetLoggersDir("/tmp/polaris/log"); err != nil {

```go
if err := api.SetLoggersLevel(api.InfoLog); err != nil {
//do error handle
// do error handle
}
```

日志级别支持NoneLog, TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog, FatalLog,设置成NoneLog,则不打印任何日志

#### 同时修改北极星日志路径及日志级别

polaris-go启动后,默认会在程序运行的当前目录创建polaris/log目录,用于存放运行过程中的日志。因此用户需要保证当前目录有写权限 假如需要修改北极星的日志打印目录以及日志级别,可以按照以下方式进行修改
polaris-go启动后,默认会在程序运行的当前目录创建polaris/log目录,用于存放运行过程中的日志。因此用户需要保证当前目录有写权限
假如需要修改北极星的日志打印目录以及日志级别,可以按照以下方式进行修改

```go
if err := api.ConfigLoggers("/tmp/polaris/log", api.InfoLog); err != nil {
//do error handle
// do error handle
}
```
Loading

0 comments on commit a917801

Please sign in to comment.