github.com/altipla-consulting/ravendb-go-client@v0.1.3/set_indexes_priority_operation.go (about) 1 package ravendb 2 3 import ( 4 "net/http" 5 ) 6 7 var _ IVoidMaintenanceOperation = &SetIndexesPriorityOperation{} 8 9 // SetIndexesPriorityOperation represents operation for setting indexes priority 10 type SetIndexesPriorityOperation struct { 11 parameters *SetIndexesPriorityParameters 12 Command *SetIndexesPriorityCommand 13 } 14 15 // NewSetIndexesPriorityOperation returns new SetIndexesPriorityParameters 16 func NewSetIndexesPriorityOperation(indexName string, priority IndexPriority) (*SetIndexesPriorityOperation, error) { 17 if indexName == "" { 18 return nil, newIllegalArgumentError("indexName cannot be empty") 19 } 20 21 p := &SetIndexesPriorityParameters{ 22 IndexNames: []string{indexName}, 23 Priority: priority, 24 } 25 return &SetIndexesPriorityOperation{ 26 parameters: p, 27 }, nil 28 } 29 30 // GetCommand returns a command 31 func (o *SetIndexesPriorityOperation) GetCommand(conventions *DocumentConventions) (RavenCommand, error) { 32 var err error 33 o.Command, err = NewSetIndexesPriorityCommand(conventions, o.parameters) 34 if err != nil { 35 return nil, err 36 } 37 return o.Command, nil 38 } 39 40 var ( 41 _ RavenCommand = &SetIndexesPriorityCommand{} 42 ) 43 44 // SetIndexesPriorityCommand represents command to set indexes priority 45 type SetIndexesPriorityCommand struct { 46 RavenCommandBase 47 48 _parameters []byte 49 } 50 51 // NewSetIndexesPriorityCommand returns new SetIndexesPriorityCommand 52 func NewSetIndexesPriorityCommand(conventions *DocumentConventions, parameters *SetIndexesPriorityParameters) (*SetIndexesPriorityCommand, error) { 53 if conventions == nil { 54 return nil, newIllegalArgumentError("conventions cannot be null") 55 } 56 if parameters == nil { 57 return nil, newIllegalArgumentError("parameters cannot be null") 58 } 59 60 // Note: compared to Java, we shortcut things by serializing to JSON 61 // here as it's simpler and faster than two-step serialization, 62 // first to map[string]interface{} and then to JSON 63 d, err := jsonMarshal(parameters) 64 panicIf(err != nil, "jsonMarshal failed with %s", err) 65 cmd := &SetIndexesPriorityCommand{ 66 RavenCommandBase: NewRavenCommandBase(), 67 68 _parameters: d, 69 } 70 cmd.ResponseType = RavenCommandResponseTypeEmpty 71 return cmd, nil 72 } 73 74 func (c *SetIndexesPriorityCommand) createRequest(node *ServerNode) (*http.Request, error) { 75 url := node.URL + "/databases/" + node.Database + "/indexes/set-priority" 76 77 return newHttpPost(url, c._parameters) 78 } 79 80 // SetIndexesPriorityParameters represents arrgument for SetIndexPriorityCommand 81 // Note: in Java it's Parameters class nested in SetIndexesPriorityOperation 82 // "Parameters" name is already taken 83 type SetIndexesPriorityParameters struct { 84 IndexNames []string `json:"IndexNames"` 85 Priority IndexPriority `json:"Priority"` 86 }