github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/head_attachment_command.go (about) 1 package ravendb 2 3 import ( 4 "net/http" 5 ) 6 7 var ( 8 _ RavenCommand = &HeadAttachmentCommand{} 9 ) 10 11 type HeadAttachmentCommand struct { 12 RavenCommandBase 13 14 _documentID string 15 _name string 16 _changeVector *string 17 18 Result string // TODO: should this be *string? 19 } 20 21 func NewHeadAttachmentCommand(documentID string, name string, changeVector *string) (*HeadAttachmentCommand, error) { 22 if stringIsBlank(documentID) { 23 return nil, newIllegalArgumentError("DocumentId cannot be null or empty") 24 } 25 if stringIsBlank(name) { 26 return nil, newIllegalArgumentError("Name cannot be null or empty") 27 } 28 29 cmd := &HeadAttachmentCommand{ 30 RavenCommandBase: NewRavenCommandBase(), 31 32 _documentID: documentID, 33 _name: name, 34 _changeVector: changeVector, 35 } 36 return cmd, nil 37 } 38 39 func (c *HeadAttachmentCommand) CreateRequest(node *ServerNode) (*http.Request, error) { 40 url := node.URL + "/databases/" + node.Database + "/attachments?id=" + urlUtilsEscapeDataString(c._documentID) + "&name=" + urlUtilsEscapeDataString(c._name) 41 42 request, err := newHttpGet(url) 43 if err != nil { 44 return nil, err 45 } 46 47 if c._changeVector != nil { 48 request.Header.Set(headersIfNoneMatch, *c._changeVector) 49 } 50 51 return request, nil 52 } 53 54 func (c *HeadAttachmentCommand) processResponse(cache *httpCache, response *http.Response, url string) (responseDisposeHandling, error) { 55 if response.StatusCode == http.StatusNotModified { 56 if c._changeVector != nil { 57 c.Result = *c._changeVector 58 } 59 return responseDisposeHandlingAutomatic, nil 60 } 61 62 if response.StatusCode == http.StatusNotFound { 63 c.Result = "" 64 return responseDisposeHandlingAutomatic, nil 65 } 66 67 res, err := gttpExtensionsGetRequiredEtagHeader(response) 68 if err != nil { 69 return responseDisposeHandlingAutomatic, err 70 } 71 if res != nil { 72 c.Result = *res 73 } 74 return responseDisposeHandlingAutomatic, nil 75 } 76 77 func (c *HeadAttachmentCommand) SetResponse(response []byte, fromCache bool) error { 78 if response != nil { 79 return throwInvalidResponse() 80 } 81 c.Result = "" 82 return nil 83 }