MCPcopy Create free account
hub / github.com/DoNewsCode/core / getBool

Function getBool

helper.go:34–57  ·  view source on GitHub ↗
(data map[string]interface{}, key ...string)

Source from the content-addressed store, hash-verified

32}
33
34func getBool(data map[string]interface{}, key ...string) (bool, error) {
35 if len(key) <= 0 {
36 panic("key must be provided at least once")
37 }
38 for i := 0; i < len(key)-1; i++ {
39 value, ok := data[key[i]]
40 if !ok {
41 return false, fmt.Errorf("%s doesn't exist", strings.Join(key[0:i+1], "."))
42 }
43 data, ok = value.(map[string]interface{})
44 if !ok {
45 return false, fmt.Errorf("%s is not a map", strings.Join(key[0:i+1], "."))
46 }
47 }
48 value, ok := data[key[len(key)-1]]
49 if !ok {
50 return false, fmt.Errorf("%s doesn't exist", strings.Join(key, "."))
51 }
52 b, ok := value.(bool)
53 if !ok {
54 return b, errors.New("must be a bool")
55 }
56 return b, nil
57}
58
59// isValidLevel tests if the given input is valid level config.
60func isValidLevel(levelCfg string) bool {

Callers 1

provideDefaultConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected