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

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  var (
     8  	_ IMaintenanceOperation = &UpdateExternalReplicationOperation{}
     9  )
    10  
    11  type UpdateExternalReplicationOperation struct {
    12  	_newWatcher *ExternalReplication
    13  
    14  	Command *UpdateExternalReplicationCommand
    15  }
    16  
    17  func NewUpdateExternalReplicationOperation(newWatcher *ExternalReplication) *UpdateExternalReplicationOperation {
    18  	return &UpdateExternalReplicationOperation{
    19  		_newWatcher: newWatcher,
    20  	}
    21  }
    22  
    23  func (o *UpdateExternalReplicationOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) {
    24  	o.Command = NewUpdateExternalReplicationCommand(o._newWatcher)
    25  	return o.Command, nil
    26  }
    27  
    28  var _ RavenCommand = &UpdateExternalReplicationCommand{}
    29  
    30  type UpdateExternalReplicationCommand struct {
    31  	RavenCommandBase
    32  
    33  	_newWatcher *ExternalReplication
    34  
    35  	Result *ModifyOngoingTaskResult
    36  }
    37  
    38  func NewUpdateExternalReplicationCommand(newWatcher *ExternalReplication) *UpdateExternalReplicationCommand {
    39  	cmd := &UpdateExternalReplicationCommand{
    40  		RavenCommandBase: NewRavenCommandBase(),
    41  
    42  		_newWatcher: newWatcher,
    43  	}
    44  	return cmd
    45  }
    46  
    47  func (c *UpdateExternalReplicationCommand) createRequest(node *ServerNode) (*http.Request, error) {
    48  	url := node.URL + "/databases/" + node.Database + "/admin/tasks/external-replication"
    49  
    50  	m := map[string]interface{}{
    51  		"Watcher": c._newWatcher,
    52  	}
    53  	d, err := jsonMarshal(m)
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  	return newHttpPost(url, d)
    58  }
    59  
    60  func (c *UpdateExternalReplicationCommand) setResponse(response []byte, fromCache bool) error {
    61  	if len(response) == 0 {
    62  		return throwInvalidResponse()
    63  	}
    64  
    65  	return jsonUnmarshal(response, &c.Result)
    66  }