github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/object/service-get-metadata.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package object
     4  
     5  import (
     6  	etime "../earth-time"
     7  	"../protocol"
     8  )
     9  
    10  func (ser *getMetadataService) ServeSRPC(st protocol.Stream, srpcReq protocol.SRPCRequest) (res protocol.Syllab, err protocol.Error) {
    11  	var srpcRequestPayload = srpcReq.Payload()
    12  	var reqAsSyllab = getRequestSyllab(srpcRequestPayload)
    13  	err = reqAsSyllab.CheckSyllab(srpcRequestPayload)
    14  	if err != nil {
    15  		return
    16  	}
    17  
    18  	var objMetadata protocol.ObjectMetadata
    19  	objMetadata, err = getMetadata(reqAsSyllab)
    20  	if err != nil {
    21  		return
    22  	}
    23  	switch md := objMetadata.(type) {
    24  	case Metadata:
    25  		res = md
    26  	default:
    27  		var tempMetadata = metadata{
    28  			id:             objMetadata.ID(),
    29  			writeTime:      etime.Time(objMetadata.WriteTime().Unix()),
    30  			mediaTypeID:    objMetadata.MediaTypeID(),
    31  			compressTypeID: objMetadata.CompressTypeID(),
    32  			dataLength:     objMetadata.DataLength(),
    33  		}
    34  		res = &tempMetadata
    35  	}
    36  	return
    37  }
    38  
    39  func getMetadata(req getMetadataRequest) (metadata protocol.ObjectMetadata, err protocol.Error) {
    40  	metadata, err = protocol.OS.ObjectDirectory().Metadata(req.ObjectID(), req.ObjectStructureID())
    41  	return
    42  }