github.com/altipla-consulting/ravendb-go-client@v0.1.3/server_operation_executor.go (about) 1 package ravendb 2 3 type ServerOperationExecutor struct { 4 requestExecutor *ClusterRequestExecutor 5 } 6 7 func NewServerOperationExecutor(store *DocumentStore) *ServerOperationExecutor { 8 res := &ServerOperationExecutor{} 9 urls := store.GetUrls() 10 cert := store.Certificate 11 trustStore := store.TrustStore 12 conv := store.GetConventions() 13 if conv.IsDisableTopologyUpdates() { 14 res.requestExecutor = ClusterRequestExecutorCreateForSingleNode(urls[0], cert, trustStore, conv) 15 } else { 16 res.requestExecutor = ClusterRequestExecutorCreate(urls, cert, trustStore, conv) 17 } 18 fn := func(store *DocumentStore) { 19 res.requestExecutor.Close() 20 } 21 store.AddAfterCloseListener(fn) 22 return res 23 } 24 25 func (e *ServerOperationExecutor) Send(operation IServerOperation) error { 26 command, err := operation.GetCommand(e.requestExecutor.GetConventions()) 27 if err != nil { 28 return err 29 } 30 return e.requestExecutor.ExecuteCommand(command, nil) 31 } 32 33 func (e *ServerOperationExecutor) SendAsync(operation IServerOperation) (*Operation, error) { 34 requestExecutor := e.requestExecutor 35 command, err := operation.GetCommand(requestExecutor.GetConventions()) 36 if err != nil { 37 return nil, err 38 } 39 if err = requestExecutor.ExecuteCommand(command, nil); err != nil { 40 return nil, err 41 } 42 result := getCommandOperationIDResult(command) 43 return NewServerWideOperation(requestExecutor, requestExecutor.GetConventions(), result.OperationID), nil 44 } 45 46 func (e *ServerOperationExecutor) Close() { 47 e.requestExecutor.Close() 48 e.requestExecutor = nil 49 }