upadate check wild key
This commit is contained in:
16
key/wild.go
16
key/wild.go
@@ -1,15 +1,21 @@
|
||||
package key
|
||||
|
||||
import "slices"
|
||||
|
||||
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 {
|
||||
return false
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
Reference in New Issue
Block a user