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

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  var _ IMaintenanceOperation = &GetIndexesStatisticsOperation{}
     8  
     9  type GetIndexesStatisticsOperation struct {
    10  	Command *GetIndexesStatisticsCommand
    11  }
    12  
    13  func NewGetIndexesStatisticsOperation() *GetIndexesStatisticsOperation {
    14  	return &GetIndexesStatisticsOperation{}
    15  }
    16  
    17  func (o *GetIndexesStatisticsOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) {
    18  	o.Command = NewGetIndexesStatisticsCommand()
    19  	return o.Command, nil
    20  }
    21  
    22  var (
    23  	_ RavenCommand = &GetIndexesStatisticsCommand{}
    24  )
    25  
    26  type GetIndexesStatisticsCommand struct {
    27  	RavenCommandBase
    28  
    29  	Result []*IndexStats
    30  }
    31  
    32  func NewGetIndexesStatisticsCommand() *GetIndexesStatisticsCommand {
    33  
    34  	res := &GetIndexesStatisticsCommand{
    35  		RavenCommandBase: NewRavenCommandBase(),
    36  	}
    37  	res.IsReadRequest = true
    38  	return res
    39  }
    40  
    41  func (c *GetIndexesStatisticsCommand) createRequest(node *ServerNode) (*http.Request, error) {
    42  	url := node.URL + "/databases/" + node.Database + "/indexes/stats"
    43  
    44  	return newHttpGet(url)
    45  }
    46  
    47  func (c *GetIndexesStatisticsCommand) setResponse(response []byte, fromCache bool) error {
    48  	if response == nil {
    49  		return throwInvalidResponse()
    50  	}
    51  
    52  	var res struct {
    53  		Results []*IndexStats `json:"Results"`
    54  	}
    55  	err := jsonUnmarshal(response, &res)
    56  	if err != nil {
    57  		return err
    58  	}
    59  	c.Result = res.Results
    60  	return nil
    61  }