github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/object/directory.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package object
     4  
     5  import (
     6  	"../protocol"
     7  )
     8  
     9  // Directory implement protocol.ObjectDirectory to be distributed object storage
    10  type Directory struct{}
    11  
    12  // Get return the whole object as metadata and data
    13  func (dir *Directory) Get(uuid [32]byte, structureID uint64) (obj protocol.Object, err protocol.Error) {
    14  	// TODO::: First read from local OS (related lib) as cache
    15  
    16  	var req = GetRequest{
    17  		objectID:          uuid,
    18  		objectStructureID: structureID,
    19  	}
    20  	obj, err = GetService.DoSRPC(req)
    21  	if err != nil {
    22  		return
    23  	}
    24  
    25  	// TODO::: Write to local OS as cache if not enough storage exist do GC(Garbage Collector)
    26  	return
    27  }
    28  
    29  // Read return requested part of object data.
    30  func (dir *Directory) Read(uuid [32]byte, osID uint64, offset, limit uint64) (data []byte, err protocol.Error) {
    31  	// TODO::: First read from local storage as cache
    32  
    33  	var req = ReadRequest{
    34  		objectID:          uuid,
    35  		objectStructureID: osID,
    36  		offset:            offset,
    37  		limit:             limit,
    38  	}
    39  	var res readResponse
    40  	res, err = ReadService.DoSRPC(req)
    41  	if err != nil {
    42  		return
    43  	}
    44  	data = res.Data()
    45  	return
    46  }
    47  
    48  func (dir *Directory) Save(data protocol.Codec) (metadata protocol.ObjectMetadata, err protocol.Error) {
    49  	return SaveService.DoSRPC(data)
    50  }
    51  
    52  // Delete delete the object by object-UUID
    53  func (dir *Directory) Delete(uuid [32]byte, structureID uint64) (err protocol.Error) {
    54  	var req = DeleteRequest{
    55  		requestType:       RequestTypeBroadcast,
    56  		objectID:          uuid,
    57  		objectStructureID: structureID,
    58  	}
    59  	err = DeleteService.DoSRPC(req)
    60  	return
    61  }
    62  
    63  // Wipe make invisible by remove from primary index & write random data to object location
    64  func (dir *Directory) Wipe(uuid [32]byte, structureID uint64) (err protocol.Error) {
    65  	return
    66  }