mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 05:01:10 -05:00
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.1.8 to 2.2.2. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.1.8...v2.2.2) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package maputil
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/gookit/goutil/reflects"
|
|
)
|
|
|
|
// HasKey check of the given map.
|
|
func HasKey(mp, key any) (ok bool) {
|
|
rftVal := reflect.Indirect(reflect.ValueOf(mp))
|
|
if rftVal.Kind() != reflect.Map {
|
|
return
|
|
}
|
|
|
|
for _, keyRv := range rftVal.MapKeys() {
|
|
if reflects.IsEqual(keyRv.Interface(), key) {
|
|
return true
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// HasOneKey check of the given map. return the first exist key
|
|
func HasOneKey(mp any, keys ...any) (ok bool, key any) {
|
|
rftVal := reflect.Indirect(reflect.ValueOf(mp))
|
|
if rftVal.Kind() != reflect.Map {
|
|
return
|
|
}
|
|
|
|
for _, key = range keys {
|
|
for _, keyRv := range rftVal.MapKeys() {
|
|
if reflects.IsEqual(keyRv.Interface(), key) {
|
|
return true, key
|
|
}
|
|
}
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|
|
// HasAllKeys check of the given map. return the first not exist key
|
|
func HasAllKeys(mp any, keys ...any) (ok bool, noKey any) {
|
|
rftVal := reflect.Indirect(reflect.ValueOf(mp))
|
|
if rftVal.Kind() != reflect.Map {
|
|
return
|
|
}
|
|
|
|
for _, key := range keys {
|
|
var exist bool
|
|
for _, keyRv := range rftVal.MapKeys() {
|
|
if reflects.IsEqual(keyRv.Interface(), key) {
|
|
exist = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !exist {
|
|
return false, key
|
|
}
|
|
}
|
|
|
|
return true, nil
|
|
}
|