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