Skip to content

Commit

Permalink
feat: implement access_token and refresh_token, update the logic of a…
Browse files Browse the repository at this point in the history
…uthenticator
  • Loading branch information
SmilingSea committed Nov 13, 2024
1 parent 054ec7c commit 29e7efe
Show file tree
Hide file tree
Showing 70 changed files with 8,429 additions and 4,386 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
name: Format
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
Expand All @@ -38,8 +38,8 @@ jobs:
name: Vet
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
Expand All @@ -62,6 +62,38 @@ jobs:
with:
version: latest
args: --timeout=10m
test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
- name: Install dependencies
run: go mod tidy
- name: Run tests
run: make test # 使用我们自己的测试命令
- name: Check the number of changed lines
run: | # 比较基础提交和最新提交的差别,新增代码行数不超过 10 行则不需要检查
LINES_ADDED=$(git diff --numstat ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} pkg/ | awk '{ add += $1 } END { printf add }')
echo "lines added: $LINES_ADDED"
if [[ $LINES_ADDED -lt 10 ]]; then
echo "NEED_TO_CHECK=false" >> $GITHUB_ENV
else
echo "NEED_TO_CHECK=true" >> $GITHUB_ENV
fi
- name: Upload results to Codecov
if: ${{ (env.NEED_TO_CHECK == 'true') || (github.event_name != 'pull_request') }}
uses: codecov/codecov-action@v4
with:
flags: unittest
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.txt
fail_ci_if_error: true
verbose: true

license:
name: License
Expand All @@ -71,4 +103,4 @@ jobs:
- name: Check license header
run: |
make license && git add pkg cmd &&
git diff --cached --exit-code || (echo 'Please run "make license" to add license headers' && exit 1);
git diff --cached --exit-code || (echo 'Please run "make license" to add license headers' && exit 1);
197 changes: 175 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
run:
# default concurrency is the available CPU number
concurrency: 16

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
Expand All @@ -23,23 +19,81 @@ run:
output:
# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true


# all available settings of specific linters
linters-settings:
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
nakedret:
# Make an issue if func has more lines of code than this setting, and it has naked returns.
# Default: 30
max-func-lines: 31
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/west2-online
gci:
# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/west2-online) # Custom section: groups all imports with the specified Prefix.
# - blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
# - dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
# - alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
# - localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
# Skip generated files.
# Default: true
skip-generated: true
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true
# Drops lexical ordering for custom sections.
# Default: false
no-lex-order: true
nilnil:
# List of return types to check.
# Default: ["ptr", "func", "iface", "map", "chan", "uintptr", "unsafeptr"]
checked-types:
- ptr
- func
- iface
- map
- chan
- uintptr
- unsafeptr
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors.
# See the https://github.com/polyfloyd/go-errorlint for caveats.
errorf: true
# Permit more than 1 %w verb, valid per Go 1.20 (Requires errorf:true)
# Default: true
errorf-multi: true
# Check for plain type assertions and type switches.
# Default: true
asserts: true
# Check for plain error comparisons.
# Default: true
comparison: true
# Allowed errors.
# Default: []
allowed-errors:
- err: "io.EOF"
fun: "example.com/pkg.Read"
# Allowed error "wildcards".
# Default: []
allowed-errors-wildcard:
- err: "github.com/west2-online/fzuhelper-server/pkg/errno"
fun: "github.com/west2-online/fzuhelper-server/pkg/errno"
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
Expand All @@ -49,22 +103,121 @@ linters-settings:
checks:
- all
- -SA1019
lll:
# Max line length, lines longer will be reported.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
# Default: 120.
line-length: 160
# Tab width in spaces.
# Default: 1
tab-width: 1
mnd:
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
checks:
- argument
- case
- condition
- operation
- return
- assign
# List of numbers to exclude from analysis.
# The numbers should be written as string.
# Values always ignored: "1", "1.0", "0" and "0.0"
# Default: []
ignored-numbers:
- '0666'
- '0755'
- '42'
# List of file patterns to exclude from analysis.
# Values always ignored: `.+_test.go`
# Default: []
ignored-files:
- 'magic1_.+\.go$'
# List of function patterns to exclude from analysis.
# Following functions are always ignored: `time.Date`,
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
# Default: []
ignored-functions:
- '^math\.'
- '^http\.StatusText$'
makezero:
# Allow only slices initialized with a length of zero.
# Default: false
always: false
nestif:
# Minimal complexity of if statements to report.
# Default: 5
min-complexity: 6
tagalign:
# Align and sort can be used together or separately.
#
# Whether enable align. If true, the struct tags will be aligned.
# e.g.:
# type FooBar struct {
# Bar string `json:"bar" validate:"required"`
# FooFoo int8 `json:"foo_foo" validate:"required"`
# }
# will be formatted to:
# type FooBar struct {
# Bar string `json:"bar" validate:"required"`
# FooFoo int8 `json:"foo_foo" validate:"required"`
# }
# Default: true.
align: true
# Whether enable tags sort.
# If true, the tags will be sorted by name in ascending order.
# e.g.: `xml:"bar" json:"bar" validate:"required"` -> `json:"bar" validate:"required" xml:"bar"`
# Default: true
sort: true
# Specify the order of tags, the other tags will be sorted by name.
# This option will be ignored if `sort` is false.
# Default: []
order:
- json
- yaml
- yml
- toml
- mapstructure
- binding
- validate
# Whether enable strict style.
# In this style, the tags will be sorted and aligned in the dictionary order,
# and the tags with the same name will be aligned together.
# Note: This option will be ignored if 'align' or 'sort' is false.
# Default: false
strict: true

linters:
fast: false
disable-all: true
enable:
- errcheck
- staticcheck
- typecheck
- unused
- misspell
- nolintlint
- goimports
- nakedret
- unconvert
- whitespace
- govet
- gosimple
- ineffassign
- gocritic
- errcheck # 错误检查
- staticcheck # 静态检查
- unused # 检查未使用的变量、常量、函数和类型
- misspell # 检查常见的拼写错误的英文单词
- nolintlint # 报告不正确或不充分的 nolint 指令
- goimports # 检查包导入是否按 goimport 命令格式化
- nakedret # 检查具有裸返回(func with naked returns)的函数包体是否过大
- unconvert # 删除不必要的类型转换
- whitespace # 检查不必要的换行符
- govet # 与 go vet 大致相同
- gosimple # 简化代码
- ineffassign # 检测现有变量的赋值何时未被使用
- gocritic # 提供诊断功能,检查错误、性能和样式问题
- importas # 强制使用一致的包导入别名
- gci # 控制包导入顺序
- errorlint # 检查错误处理代码合规性
- nilerr # 检查当产生错误时仍然返回 nil 的情况
- asciicheck # 检查非 ASCII 字符
- copyloopvar # 检查循环变量是否在闭包中被复制
- decorder # 检查类型、常量、变量和函数的声明顺序和数量
- forcetypeassert # 查找强制类型断言
- lll # 检查行的长度
- mnd # 检查魔数,魔数应该尽量放置在常量中
- inamedparam # 检查函数参数的命名
- makezero # 检查是否存在非零长初始化的切片
- mirror # 报告 bytes/strings 的错误 mirror 用法
- nestif # 检查是否存在深度嵌套的 if
- tagalign # 检查结构体标签是否对齐,支持自动修正
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ hertz-gen-api:
hz update -idl ${IDL_PATH}/api.thrift

# 单元测试
# -gcflags="all=-l -N": -l 表示禁用内联优化,-N 表示禁用优化
# -parallel=16: 可以并行运行的测试数量,这里设置为 16
# -p=16: 指定并行构建的最大数量,这里设置为 16
# -covermode=atomic: 设置覆模式为原子模式
# -race: 启用竞态检测,检查并发代码中的数据竞争问题
# 我们通过`go list`来列出所有的包,然后通过`grep`来过滤掉不需要测试的包
.PHONY: test
test:
go test -v -gcflags="all=-l -N" -coverprofile=coverage.txt -parallel=16 -p=16 -covermode=atomic -race -coverpkg=./... \
`go list ./... | grep -E -v "kitex_gen|.github|idl|docs|config|deploy"`
`go list ./... | grep -E -v "kitex_gen|.github|idl|docs|config|deploy|docker"`

# 构建指定对象,构建后在没有给 BUILD_ONLY 参的情况下会自动运行,需要熟悉 tmux 环境
# 用于本地调试
Expand Down Expand Up @@ -185,7 +191,7 @@ vet:
# 代码格式校验
.PHONY: lint
lint:
golangci-lint run --config=./.golangci.yml
golangci-lint run --config=./.golangci.yml --tests --allow-parallel-runners --sort-results --show-stats --print-resources-usage

# 一键修正规范并执行代码检查
.PHONY: verify
Expand Down
8 changes: 6 additions & 2 deletions api/handler/api/launch_screen_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 29e7efe

Please sign in to comment.