// keyWithDefaultFunc returns or accumulates key dependencies that have a // default value. func keyWithDefaultFunc(b *Brain, used, missing *dep.Set) func(string, string) (string, error) { return func(s, def string) (string, error) { if len(s) == 0 { return def, nil } d, err := dep.NewKVGetQuery(s) if err != nil { return "", err } used.Add(d) if value, ok := b.Recall(d); ok { if value == nil || value.(string) == "" { return def, nil } return value.(string), nil } missing.Add(d) return def, nil } }
// keyFunc returns or accumulates key dependencies. func keyFunc(b *Brain, used, missing *dep.Set) func(string) (string, error) { return func(s string) (string, error) { if len(s) == 0 { return "", nil } d, err := dep.NewKVGetQuery(s) if err != nil { return "", err } d.EnableBlocking() used.Add(d) if value, ok := b.Recall(d); ok { if value == nil { return "", nil } return value.(string), nil } missing.Add(d) return "", nil } }
// keyExistsFunc returns true if a key exists, false otherwise. func keyExistsFunc(b *Brain, used, missing *dep.Set) func(string) (bool, error) { return func(s string) (bool, error) { if len(s) == 0 { return false, nil } d, err := dep.NewKVGetQuery(s) if err != nil { return false, err } used.Add(d) if value, ok := b.Recall(d); ok { return value != nil, nil } missing.Add(d) return false, nil } }