upadate check wild key

This commit is contained in:
2026-01-03 14:07:55 +03:00
parent f277358d9a
commit 87c0106ee5
3 changed files with 35 additions and 5 deletions

View File

@@ -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
View 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"))
}