本文整理匯總了Golang中camlistore/org/pkg/sorted.KeyValue.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang KeyValue.Close方法的具體用法?Golang KeyValue.Close怎麽用?Golang KeyValue.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類camlistore/org/pkg/sorted.KeyValue
的用法示例。
在下文中一共展示了KeyValue.Close方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newStorage
// newStorage returns a new storage in path root with the given maxFileSize,
// or defaultMaxFileSize (512MB) if <= 0
func newStorage(root string, maxFileSize int64, indexConf jsonconfig.Obj) (s *storage, err error) {
fi, err := os.Stat(root)
if os.IsNotExist(err) {
return nil, fmt.Errorf("storage root %q doesn't exist", root)
}
if err != nil {
return nil, fmt.Errorf("Failed to stat directory %q: %v", root, err)
}
if !fi.IsDir() {
return nil, fmt.Errorf("storage root %q exists but is not a directory.", root)
}
var index sorted.KeyValue
if len(indexConf) > 0 {
index, err = sorted.NewKeyValue(indexConf)
} else {
index, err = kvfile.NewStorage(filepath.Join(root, indexKV))
}
if err != nil {
return nil, err
}
defer func() {
if err != nil {
index.Close()
}
}()
if maxFileSize <= 0 {
maxFileSize = defaultMaxFileSize
}
// Be consistent with trailing slashes. Makes expvar stats for total
// reads/writes consistent across diskpacked targets, regardless of what
// people put in their low level config.
root = strings.TrimRight(root, `\/`)
s = &storage{
root: root,
index: index,
maxFileSize: maxFileSize,
Generationer: local.NewGenerationer(root),
}
s.mu.Lock()
defer s.mu.Unlock()
if err := s.openAllPacks(); err != nil {
return nil, err
}
if _, _, err := s.StorageGeneration(); err != nil {
return nil, fmt.Errorf("Error initialization generation for %q: %v", root, err)
}
return s, nil
}