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