github.com/altipla-consulting/ravendb-go-client@v0.1.3/put_attachment_command_data.go (about)

     1  package ravendb
     2  
     3  import "io"
     4  
     5  type PutAttachmentCommandData struct {
     6  	*CommandData
     7  	stream      io.Reader
     8  	contentType string
     9  }
    10  
    11  var _ ICommandData = &PutAttachmentCommandData{} // verify interface match
    12  
    13  func NewPutAttachmentCommandData(documentID string, name string, stream io.Reader, contentType string, changeVector *string) (*PutAttachmentCommandData, error) {
    14  	if stringIsBlank(documentID) {
    15  		return nil, newIllegalArgumentError("DocumentId cannot be null or empty")
    16  	}
    17  	if stringIsBlank(name) {
    18  		return nil, newIllegalArgumentError("Name cannot be null or empty")
    19  	}
    20  
    21  	res := &PutAttachmentCommandData{
    22  		CommandData: &CommandData{
    23  			Type:         CommandAttachmentPut,
    24  			ID:           documentID,
    25  			Name:         name,
    26  			ChangeVector: changeVector,
    27  		},
    28  		stream:      stream,
    29  		contentType: contentType,
    30  	}
    31  	return res, nil
    32  }
    33  
    34  func (d *PutAttachmentCommandData) serialize(conventions *DocumentConventions) (interface{}, error) {
    35  	res := d.baseJSON()
    36  	res["Name"] = d.Name
    37  	if d.contentType != "" {
    38  		res["ContentType"] = d.contentType
    39  	} else {
    40  		res["ContentType"] = nil
    41  	}
    42  	res["Type"] = "AttachmentPUT"
    43  	res["ChangeVector"] = d.ChangeVector
    44  	return res, nil
    45  }
    46  
    47  func (d *PutAttachmentCommandData) getStream() io.Reader {
    48  	return d.stream
    49  }
    50  
    51  func (d *PutAttachmentCommandData) GetContentType() string {
    52  	return d.contentType
    53  }