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

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