Skip to content

Commit

Permalink
Merge pull request #141 from CSUSTers/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
icceey authored Jan 3, 2023
2 parents 71a9a2b + 2c5a3ec commit 7155a19
Show file tree
Hide file tree
Showing 27 changed files with 1,067 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.18
go-version: ^1.19

- name: Get source
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.45
version: v1.50
args: --issues-exit-code=1
only-new-issues: false
skip-go-installation: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ^1.18
go-version: ^1.19

- name: Get source
uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ got
csust-got
got.exe
csust-got.exe
a.http
a.http
.idea/GitLink.xml
140 changes: 42 additions & 98 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# options for analysis running
run:
go: "1.18"
go: "1.19"
# default concurrency is a available CPU number
concurrency: 8

Expand Down Expand Up @@ -104,13 +104,6 @@ linters-settings:
# consider enums only in package scopes, not in inner scopes
package-scope-only: false

forbidigo:
# Forbid the following identifiers (identifiers are written using regexp):
forbid:
- 'fmt\.Print.*'
# Exclude godoc examples from forbidigo checks. Default is true.
exclude_godoc_examples: true

goconst:
# minimal length of string constant, 3 by default
min-len: 3
Expand Down Expand Up @@ -138,14 +131,12 @@ linters-settings:
- nestingReduce
- ruleguard
- truncateCmp
# - unnamedresult

# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
- regexpMust
- hugeParam
- rangeValCopy
- typeDefFirst

# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
Expand All @@ -164,9 +155,6 @@ linters-settings:
elseif:
# whether to skip balanced if-else pairs (default true)
skipBalanced: true
hugeParam:
# size in bytes that makes the warning trigger (default 80)
sizeThreshold: 80
nestingReduce:
# min number of statements inside a branch to trigger a warning (default 5)
bodyWidth: 5
Expand All @@ -175,11 +163,6 @@ linters-settings:
sizeThreshold: 512
# whether to check test functions (default true)
skipTestFuncs: true
rangeValCopy:
# size in bytes that makes the warning trigger (default 128)
sizeThreshold: 128
# whether to check test functions (default true)
skipTestFuncs: true
ruleguard:
# Enable debug to identify which 'Where' condition was rejected.
# The value of the parameter is the name of a function in a ruleguard file.
Expand Down Expand Up @@ -217,9 +200,7 @@ linters-settings:
underef:
# whether to skip (*x).method() calls where x is a pointer receiver (default true)
skipRecvDeref: true
unnamedResult:
# whether to check exported functions
checkExported: true


godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
Expand All @@ -229,12 +210,12 @@ linters-settings:
- OPTIMIZE # marks code that should be optimized before merging
- HACK # marks hack-arounds that should be removed before merging

gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
# gofmt:
# # simplify code: gofmt with `-s` option, true by default
# simplify: true

gofumpt:
lang-version: "1.18"
lang-version: "1.19"

# Choose whether or not to use the extra rules that are disabled
# by default
Expand Down Expand Up @@ -282,7 +263,7 @@ linters-settings:
truncate: "32"

gosimple:
go: "1.18"
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: [ "all" ]

Expand Down Expand Up @@ -311,13 +292,6 @@ linters-settings:
- fieldalignment
# disable-all: false

ifshort:
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
# Has higher priority than max-decl-chars.
max-decl-lines: 1
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
max-decl-chars: 30

nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
Expand All @@ -326,17 +300,18 @@ linters-settings:
# minimal complexity of if statements to report, 5 by default
min-complexity: 5

nolintlint:
# Disable to ensure that all nolint directives actually have an effect. Default is false.
allow-unused: false
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: true
# Exclude following linters from requiring an explanation. Default is [].
allow-no-explanation: [ ]
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
require-specific: true
# nolintlint:
# # Disable to ensure that all nolint directives actually have an effect. Default is false.
# allow-unused: true
# # Disable to ensure that nolint directives don't have a leading space. Default is true.
# # allow-leading-space: true
# allow-leading-whitespace: true
# # Exclude following linters from requiring an explanation. Default is [].
# allow-no-explanation: [ ]
# # Enable to require an explanation of nonzero length after each nolint directive. Default is false.
# require-explanation: true
# # Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
# require-specific: true

prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
Expand Down Expand Up @@ -385,24 +360,24 @@ linters-settings:
# - name: bare-return
- name: blank-imports
- name: bool-literal-in-expr
- name: cognitive-complexity
arguments: [12]
- name: confusing-results
# - name: cognitive-complexity
# arguments: [12]
# - name: confusing-results
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: cyclomatic
arguments: [8]
# - name: context-keys-type
# - name: cyclomatic
# arguments: [8]
- name: defer
- name: duplicated-imports
- name: early-return
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
# - name: errorf
- name: exported
- name: function-length
arguments: [40, 200]
# - name: function-length
# arguments: [40, 200]
- name: get-return
- name: identical-branches
- name: if-return
Expand All @@ -413,28 +388,28 @@ linters-settings:
#- name: optimize-operands-order
- name: range
- name: range-val-in-closure
- name: range-val-address
# - name: range-val-address
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
# - name: string-of-int
- name: string-format
- name: struct-tag
- name: superfluous-else
#- name: time-equal
- name: var-declaration
- name: unhandled-error
# - name: var-declaration
# - name: unhandled-error
- name: unnecessary-stmt
- name: unreachable-code
- name: useless-break
- name: waitgroup-by-value

staticcheck:
go: "1.18"
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: [ "all" ]

stylecheck:
go: "1.18"
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: [ "all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022" ]
# https://staticcheck.io/docs/options#dot_import_whitelist
Expand All @@ -445,37 +420,11 @@ linters-settings:
# https://staticcheck.io/docs/options#http_status_code_whitelist
http-status-code-whitelist: [ "200", "400", "404", "500" ]

tagliatelle:
# check the struck tag name case
case:
# use the struct field name to check the name of the struct tag
use-field-name: true
rules:
# any struct tag type can be used.
# support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`
json: camel
yaml: camel
xml: camel
bson: camel
avro: snake
mapstructure: kebab

tenv:
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
all: false

unparam:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false

unused:
# Select the Go version to target. The default is '1.13'.
go: "1.18"

varnamelen:
# The longest distance, in source lines, that is being considered a "small scope." (defaults to 5)
# Variables used in at most this many lines will be ignored.
Expand Down Expand Up @@ -507,10 +456,6 @@ linters-settings:
- i int
- const C

whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature

wrapcheck:
# An array of strings that specify substrings of signatures to ignore.
# If this set, it will override the default set of ignored signatures.
Expand Down Expand Up @@ -540,21 +485,20 @@ linters:
- errorlint
- exhaustive
- exportloopref
- forbidigo
- gocognit
# - forbidigo
# - gocognit
- goconst
- gocritic
- godox
- goerr113
- gofmt
- goimports
# - gofmt
# - goimports
- gomoddirectives
- gosec
- govet
- ifshort
- nakedret
- nestif
- nolintlint
# - nolintlint
- prealloc
- predeclared
- revive
Expand All @@ -565,11 +509,11 @@ linters:
# - noctx
# - rowserrcheck
# - sqlclosecheck
# - stylecheck
# - tparallel
- stylecheck
- tparallel
# - unparam
# - wastedassign
- whitespace
# - whitespace
disable:
- typecheck
- structcheck
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: go
go: 1.18
go: 1.19
scripts:
- make build
- echo "Test Complete"
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ worker: 4 # number of goroutine to recv update [int]
token: ""
proxy: "" # [http:// | socks5://] host:port
listen: ":7777"
skip_duration: 0 # skip expired message, duration in seconds, set to 0 to disable [int]

black_list:
enabled: true
Expand Down
16 changes: 8 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func NewBotConfig() *Config {
type Config struct {
Bot *Bot

Token string
Proxy string
Listen string
DebugMode bool
Worker int
Token string
Proxy string
Listen string
DebugMode bool
SkipDuration int64

RedisConfig *redisConfig
RestrictConfig *restrictConfig
Expand Down Expand Up @@ -92,9 +92,9 @@ func readConfig() {
// base config
BotConfig.DebugMode = viper.GetBool("debug")
BotConfig.Token = viper.GetString("token")
BotConfig.Worker = viper.GetInt("worker")
BotConfig.Proxy = viper.GetString("proxy")
BotConfig.Listen = viper.GetString("listen")
BotConfig.SkipDuration = viper.GetInt64("skip_duration")

// other
BotConfig.RedisConfig.readConfig()
Expand All @@ -114,8 +114,8 @@ func checkConfig() {
if BotConfig.DebugMode {
zap.L().Warn("DEBUG MODE IS ON")
}
if BotConfig.Worker <= 0 {
BotConfig.Worker = 1
if BotConfig.SkipDuration < 0 {
BotConfig.SkipDuration = 0
}

BotConfig.RedisConfig.checkConfig()
Expand Down
Loading

0 comments on commit 7155a19

Please sign in to comment.