MCPcopy
hub / github.com/perkeep/perkeep / NewKeyValue

Function NewKeyValue

pkg/sorted/kv.go:228–251  ·  view source on GitHub ↗

NewKeyValue returns a KeyValue as defined by cfg. It returns an error of type NeedWipeError when the returned KeyValue should be fixed with Wipe.

(cfg jsonconfig.Obj)

Source from the content-addressed store, hash-verified

226// It returns an error of type NeedWipeError when the returned KeyValue should
227// be fixed with Wipe.
228func NewKeyValue(cfg jsonconfig.Obj) (KeyValue, error) {
229 var s KeyValue
230 var err error
231 typ := cfg.RequiredString("type")
232 ctor, ok := ctors[typ]
233 if typ != "" && !ok {
234 return nil, fmt.Errorf("Invalid sorted.KeyValue type %q", typ)
235 }
236 if ok {
237 s, err = ctor(cfg)
238 if err != nil {
239 we, ok := err.(NeedWipeError)
240 if !ok {
241 return nil, fmt.Errorf("error from %q KeyValue: %v", typ, err)
242 }
243 if err := cfg.Validate(); err != nil {
244 return nil, err
245 }
246 we.Msg = fmt.Sprintf("error from %q KeyValue: %v", typ, err)
247 return s, we
248 }
249 }
250 return s, cfg.Validate()
251}
252
253// NewKeyValueMaybeWipe calls NewKeyValue and wipes the KeyValue if, and only
254// if, NewKeyValue has returned a NeedWipeError.

Callers 15

newFromConfigFunction · 0.92
newFromConfigFunction · 0.92
TestKvfileKVFunction · 0.92
TestPostgreSQLKVFunction · 0.92
TestMongoKVFunction · 0.92
TestMySQLKVFunction · 0.92
TestRollbackFunction · 0.92
TestSQLiteKVFunction · 0.92
TestLeveldbKVFunction · 0.92
newFromConfigFunction · 0.92
newMySQLSortedFunction · 0.92
newMongoSortedFunction · 0.92

Calls

no outgoing calls

Tested by 11

TestKvfileKVFunction · 0.74
TestPostgreSQLKVFunction · 0.74
TestMongoKVFunction · 0.74
TestMySQLKVFunction · 0.74
TestRollbackFunction · 0.74
TestSQLiteKVFunction · 0.74
TestLeveldbKVFunction · 0.74
newMySQLSortedFunction · 0.74
newMongoSortedFunction · 0.74
newPostgresSortedFunction · 0.74
newSortedFunction · 0.74