github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/get_index_errors_operation.go (about) 1 package ravendb 2 3 import ( 4 "net/http" 5 ) 6 7 var ( 8 _ IMaintenanceOperation = &GetIndexErrorsOperation{} 9 ) 10 11 type GetIndexErrorsOperation struct { 12 indexNames []string 13 14 Command *GetIndexErrorsCommand 15 } 16 17 func NewGetIndexErrorsOperation(indexNames []string) *GetIndexErrorsOperation { 18 return &GetIndexErrorsOperation{ 19 indexNames: indexNames, 20 } 21 } 22 23 func (o *GetIndexErrorsOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) { 24 o.Command = NewGetIndexErrorsCommand(o.indexNames) 25 return o.Command, nil 26 } 27 28 var _ RavenCommand = &GetIndexErrorsCommand{} 29 30 type GetIndexErrorsCommand struct { 31 RavenCommandBase 32 33 indexNames []string 34 35 Result []*IndexErrors 36 } 37 38 func NewGetIndexErrorsCommand(indexNames []string) *GetIndexErrorsCommand { 39 res := &GetIndexErrorsCommand{ 40 RavenCommandBase: NewRavenCommandBase(), 41 42 indexNames: indexNames, 43 } 44 res.IsReadRequest = true 45 return res 46 } 47 48 func (c *GetIndexErrorsCommand) CreateRequest(node *ServerNode) (*http.Request, error) { 49 url := node.URL + "/databases/" + node.Database + "/indexes/errors" 50 51 if len(c.indexNames) > 0 { 52 url += "?" 53 54 for _, indexName := range c.indexNames { 55 url += "&name=" + indexName 56 } 57 } 58 59 return newHttpGet(url) 60 } 61 62 func (c *GetIndexErrorsCommand) SetResponse(response []byte, fromCache bool) error { 63 if len(response) == 0 { 64 return throwInvalidResponse() 65 } 66 var res struct { 67 Results []*IndexErrors 68 } 69 err := jsonUnmarshal(response, &res) 70 if err != nil { 71 return err 72 } 73 c.Result = res.Results 74 return nil 75 }