本文整理汇总了Golang中github.com/akaspin/bar/proto.ID类的典型用法代码示例。如果您正苦于以下问题:Golang ID类的具体用法?Golang ID怎么用?Golang ID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ID类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WriteChunk
func (s *BlockStorage) WriteChunk(blobID, chunkID proto.ID, size int64, r io.Reader) (err error) {
lock, err := s.FDLocks.Take()
if err != nil {
return
}
defer lock.Release()
n := filepath.Join(s.idPath(upload_ns, blobID), chunkID.String())
w, err := s.getCAFile(n)
if err != nil {
return
}
defer w.Close()
written, err := io.Copy(w, r)
if err != nil {
return
}
if written != size {
err = fmt.Errorf("bad chunk size for %s:%s : %d != %d",
blobID, chunkID, size, written)
return
}
err = w.Accept()
return
}
示例2: StoreChunk
// Store chunk in assemble
func (a *Assembler) StoreChunk(r io.Reader, id proto.ID) (err error) {
lock, err := a.model.FdLocks.Take()
if err != nil {
return
}
defer lock.Release()
caOpts := contentaddressable.DefaultOptions()
caOpts.Hasher = sha3.New256()
w, err := contentaddressable.NewFileWithOptions(
filepath.Join(a.Where, id.String()), caOpts)
if os.IsExist(err) {
err = nil
return
}
if err != nil {
return
}
defer w.Close()
if _, err = io.Copy(w, r); err != nil {
return
}
err = w.Accept()
return
}
示例3: commitBlob
func (a *Assembler) commitBlob(name string, id proto.ID) (err error) {
dst := filepath.Join(a.model.WD, name)
src := dst + id.String()
bak := dst + ".bak"
os.Rename(dst, bak)
if err = os.Rename(src, dst); err != nil {
os.Remove(dst)
os.Rename(bak, dst)
return
}
defer os.Remove(src)
defer os.Remove(bak)
return
}
示例4: commitBlob
func (a *Assembler) commitBlob(name string, id proto.ID) (err error) {
dst := lists.OSFromSlash(lists.OSJoin(a.model.WD, name))
src := dst + "-" + id.String()
bak := dst + "-bak"
os.Rename(dst, bak)
if err = os.Rename(src, dst); err != nil {
os.Remove(dst)
os.Rename(bak, dst)
return
}
os.Remove(src)
os.Remove(bak)
return
}
示例5: writeChunkTo
func (a *Assembler) writeChunkTo(w io.Writer, id proto.ID) (err error) {
lock, err := a.model.FdLocks.Take()
if err != nil {
return
}
defer lock.Release()
name := filepath.Join(a.Where, id.String())
r, err := os.Open(name)
if err != nil {
return
}
defer r.Close()
_, err = io.Copy(w, r)
return
}
示例6: UploadChunk
func (s *BlockStorage) UploadChunk(uploadID uuid.UUID, chunkID proto.ID, r io.Reader) (err error) {
lock, err := s.FDLocks.Take()
if err != nil {
return
}
defer lock.Release()
hexid := proto.ID(hex.EncodeToString(uploadID[:]))
n := filepath.Join(s.idPath(upload_ns, hexid), chunkID.String())
w, err := s.getCAFile(n)
if err != nil {
return
}
defer w.Close()
if _, err = io.Copy(w, r); err != nil {
return
}
err = w.Accept()
return
}
示例7: idPath
func (s *BlockStorage) idPath(ns string, id proto.ID) string {
ids := id.String()
return filepath.Join(s.Root, ns, ids[:s.Split], ids)
}