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

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