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

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  var (
     8  	_ IMaintenanceOperation = &GetCollectionStatisticsOperation{}
     9  )
    10  
    11  type GetCollectionStatisticsOperation struct {
    12  	Command *GetCollectionStatisticsCommand
    13  }
    14  
    15  func NewGetCollectionStatisticsOperation() *GetCollectionStatisticsOperation {
    16  	return &GetCollectionStatisticsOperation{}
    17  }
    18  
    19  func (o *GetCollectionStatisticsOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) {
    20  	o.Command = NewGetCollectionStatisticsCommand()
    21  	return o.Command, nil
    22  }
    23  
    24  var _ RavenCommand = &GetCollectionStatisticsCommand{}
    25  
    26  type GetCollectionStatisticsCommand struct {
    27  	RavenCommandBase
    28  
    29  	Result *CollectionStatistics
    30  }
    31  
    32  func NewGetCollectionStatisticsCommand() *GetCollectionStatisticsCommand {
    33  	cmd := &GetCollectionStatisticsCommand{
    34  		RavenCommandBase: NewRavenCommandBase(),
    35  	}
    36  	cmd.IsReadRequest = true
    37  	return cmd
    38  }
    39  
    40  func (c *GetCollectionStatisticsCommand) createRequest(node *ServerNode) (*http.Request, error) {
    41  	url := node.URL + "/databases/" + node.Database + "/collections/stats"
    42  	return newHttpGet(url)
    43  }
    44  
    45  func (c *GetCollectionStatisticsCommand) setResponse(response []byte, fromCache bool) error {
    46  	if len(response) == 0 {
    47  		return throwInvalidResponse()
    48  	}
    49  
    50  	return jsonUnmarshal(response, &c.Result)
    51  }