upadate check wild key
This commit is contained in:
16
key/wild.go
16
key/wild.go
@@ -1,15 +1,21 @@
|
|||||||
package key
|
package key
|
||||||
|
|
||||||
|
import "slices"
|
||||||
|
|
||||||
const minWildCount = 3
|
const minWildCount = 3
|
||||||
|
|
||||||
func IsWild(name string) bool {
|
func IsWild(keys ...string) bool {
|
||||||
|
return slices.ContainsFunc(keys, isWild)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Wild(name string) string {
|
||||||
|
return "{" + name + "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
func isWild(name string) bool {
|
||||||
if len(name) < minWildCount {
|
if len(name) < minWildCount {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return name[0] == '{' && name[len(name)-1] == '}'
|
return name[0] == '{' && name[len(name)-1] == '}'
|
||||||
}
|
}
|
||||||
|
|
||||||
func Wild(name string) string {
|
|
||||||
return "{" + name + "}"
|
|
||||||
}
|
|
||||||
|
|||||||
14
key/wild_test.go
Normal file
14
key/wild_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package key_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
|
"gitoa.ru/go-4devs/config/test/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWild(t *testing.T) {
|
||||||
|
require.True(t, key.IsWild(key.Wild("test")))
|
||||||
|
require.True(t, !key.IsWild("test"))
|
||||||
|
require.True(t, key.IsWild("test", key.Wild("test"), "key"))
|
||||||
|
}
|
||||||
@@ -12,3 +12,13 @@ func Truef(t *testing.T, value bool, msg string, args ...any) {
|
|||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func True(t *testing.T, value bool, args ...any) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
if !value {
|
||||||
|
t.Errorf("require:true got:%v", value)
|
||||||
|
t.Error(args...)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user