Skip to content

Commit

Permalink
ci: 更新 actions 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Mar 19, 2024
1 parent df5e47f commit 22dc37a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 39 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,20 @@ jobs:
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +63,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
18 changes: 4 additions & 14 deletions validator/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func Between[T cmp.Ordered](min, max T) func(T) bool {
if max < min {
panic("max 必须大于等于 min")
}

return func(val T) bool { return val > min && val < max }
}

Expand All @@ -20,25 +19,16 @@ func BetweenEqual[T cmp.Ordered](min, max T) func(T) bool {
if max < min {
panic("max 必须大于等于 min")
}

return func(val T) bool { return val >= min && val <= max }
}

func Less[T cmp.Ordered](num T) func(T) bool {
return func(t T) bool { return t < num }
}
func Less[T cmp.Ordered](num T) func(T) bool { return func(t T) bool { return t < num } }

func LessEqual[T cmp.Ordered](num T) func(T) bool {
return func(t T) bool { return t <= num }
}
func LessEqual[T cmp.Ordered](num T) func(T) bool { return func(t T) bool { return t <= num } }

func Great[T cmp.Ordered](num T) func(T) bool {
return func(t T) bool { return t > num }
}
func Great[T cmp.Ordered](num T) func(T) bool { return func(t T) bool { return t > num } }

func GreatEqual[T cmp.Ordered](num T) func(T) bool {
return func(t T) bool { return t >= num }
}
func GreatEqual[T cmp.Ordered](num T) func(T) bool { return func(t T) bool { return t >= num } }

// HTTPStatus 是否为有效的 HTTP 状态码
func HTTPStatus(s int) bool { return BetweenEqual(100, 599)(s) }
Expand Down
14 changes: 8 additions & 6 deletions validator/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/google/uuid"

"github.com/issue9/webfilter/gb11643"
"github.com/issue9/webfilter/gb32100"
"github.com/issue9/webfilter/internal/isbn"
Expand Down Expand Up @@ -48,14 +49,17 @@ func IP6(val string) bool {
return err == nil && ip.Is6()
}

// IP 判断是否 IP 地址
//
// 同时支持 [IP4] 和 [IP6]
func IP(val string) bool {
_, err := netip.ParseAddr(val)
return err == nil
}

// ISBN 判断是否为合法的 [ISBN] 串号
//
// 可以同时判断 ISBN10 和 ISBN13
// 可以同时判断 [ISBN10][ISBN13]
//
// [ISBN]: https://zh.wikipedia.org/wiki/%E5%9B%BD%E9%99%85%E6%A0%87%E5%87%86%E4%B9%A6%E5%8F%B7
func ISBN(val string) bool { return isbn.IsValid([]byte(val)) }
Expand Down Expand Up @@ -132,11 +136,6 @@ func Alpha(s string) bool {
return true
}

// EmptyOr 空字符串或是非空的情况下满足 v 的条件
func EmptyOr(v func(string) bool) func(string) bool {
return Or(func(s string) bool { return s == "" }, v)
}

// CNMobile 验证中国大陆的手机号码
func CNMobile(val string) bool {
// 可选的 0,86,086,+86
Expand Down Expand Up @@ -175,3 +174,6 @@ func Digit(val string) bool {

// UUID 验证 UUID 格式是否正确
func UUID(val string) bool { return uuid.Validate(val) == nil }

// Empty 字符串是否为空
func Empty(val string) bool { return val == "" }
17 changes: 8 additions & 9 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,18 @@ func Or[T any](v ...func(T) bool) func(T) bool {
}

// Not 验证器的取反
func Not[T any](v func(T) bool) func(T) bool {
return func(val T) bool { return !v(val) }
}
func Not[T any](v func(T) bool) func(T) bool { return func(val T) bool { return !v(val) } }

// Zero 是否为零值
//
// 采用 [reflect.Value.IsZero] 判断。
func Zero[T any](v T) bool { return reflect.ValueOf(v).IsZero() }

// Equal 生成判断值是否等于 v 的验证器
func Equal[T comparable](v T) func(T) bool {
return func(t T) bool { return t == v }
}
func Equal[T comparable](v T) func(T) bool { return func(t T) bool { return t == v } }

func NilOr[T any](v func(T) bool) func(T) bool {
return Or(func(v T) bool { return reflect.ValueOf(v).IsNil() }, v)
}
// Nil 是否为 nil
func Nil[T any](v T) bool { return reflect.ValueOf(v).IsNil() }

// JSON 验证是否为正确的 JSON 内容
func JSON(val []byte) bool { return json.Valid(val) }
2 changes: 1 addition & 1 deletion webfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

// Package webfilter 适合 [web.filter] 的过滤器
//
// [web/filter]: https://github.com/issue9/web
// [web/filter]: https://github.com/issue9/web/filter
package webfilter

0 comments on commit 22dc37a

Please sign in to comment.