添加自增控制
This commit is contained in:
@@ -172,3 +172,12 @@ func getJwtClaims(AuthKey string, AccessSecret *string) (jwt.MapClaims, error) {
|
||||
|
||||
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
||||
}
|
||||
|
||||
func CheckValueRange[T comparable](v T, rangevalues ...T) bool {
|
||||
for _, rv := range rangevalues {
|
||||
if v == rv {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -28,3 +28,29 @@ func TestGenJwt(t *testing.T) {
|
||||
}
|
||||
// log.Println(claims)
|
||||
}
|
||||
|
||||
func TestCheckValueRange(t *testing.T) {
|
||||
v := 1
|
||||
rv1 := []int{1, 3, 4}
|
||||
|
||||
if !CheckValueRange[int](v, rv1...) {
|
||||
t.Error("1 in [1 3 4], but is false")
|
||||
}
|
||||
|
||||
v = 2
|
||||
if CheckValueRange(v, rv1...) {
|
||||
t.Error("2 not in [1 3 4], but is true")
|
||||
}
|
||||
|
||||
vstr := "funsen123"
|
||||
rvstr := []string{"funsun123", "funsen123", "funsen23"}
|
||||
if !CheckValueRange(vstr, rvstr...) {
|
||||
t.Error("vstr in rvstr, but is false")
|
||||
}
|
||||
|
||||
vstr = "funsen1234"
|
||||
if CheckValueRange(vstr, rvstr...) {
|
||||
t.Error("vstr not in rvstr, but is true")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ var (
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "the user was not found"} // userid 不存在
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 密码错误
|
||||
|
||||
CodeSafeValueRangeErr = &StatusResponse{5040, "the value was not in values"} // 值不存在范围内
|
||||
|
||||
CodeGuestDupErr = &StatusResponse{5010, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest_id of the visitor"} // 游客guest_id序列化失败
|
||||
|
||||
|
||||
Reference in New Issue
Block a user