forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_database_names_operation.go
89 lines (71 loc) · 1.96 KB
/
get_database_names_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
87
88
89
package ravendb
import (
"net/http"
"strconv"
)
type GetDatabaseNamesOperation struct {
_start int
_pageSize int
}
func NewGetDatabaseNamesOperation(_start int, _pageSize int) *GetDatabaseNamesOperation {
return &GetDatabaseNamesOperation{
_start: _start,
_pageSize: _pageSize,
}
}
func (o *GetDatabaseNamesOperation) GetCommand(conventions *DocumentConventions) *GetDatabaseNamesCommand {
return NewGetDatabaseNamesCommand(o._start, o._pageSize)
}
var (
_ RavenCommand = &GetDatabaseNamesCommand{}
)
type GetDatabaseNamesCommand struct {
RavenCommandBase
_start int
_pageSize int
Result []string
}
func NewGetDatabaseNamesCommand(_start int, _pageSize int) *GetDatabaseNamesCommand {
cmd := &GetDatabaseNamesCommand{
RavenCommandBase: NewRavenCommandBase(),
_start: _start,
_pageSize: _pageSize,
}
cmd.IsReadRequest = true
return cmd
}
func (c *GetDatabaseNamesCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
url := node.URL + "/databases?start=" + strconv.Itoa(c._start) + "&pageSize=" + strconv.Itoa(c._pageSize) + "&namesOnly=true"
return newHttpGet(url)
}
// GetDatabaseNamesResult describes response of GetDatabaseNames command
type GetDatabaseNamesResult struct {
Databases []string `json:"Databases"`
}
func (c *GetDatabaseNamesCommand) SetResponse(response []byte, fromCache bool) error {
if len(response) == 0 {
return throwInvalidResponse()
}
var res GetDatabaseNamesResult
err := jsonUnmarshal(response, &res)
if err != nil {
return err
}
/*
JsonNode names = mapper.readTree(response);
if (!names.has("Databases")) {
throwInvalidResponse();
}
JsonNode databases = names.get("Databases");
if (!databases.isArray()) {
return throwInvalidResponse();
}
ArrayNode dbNames = (ArrayNode) databases;
string[] databaseNames = new string[dbNames.size()];
for (int i = 0; i < dbNames.size(); i++) {
databaseNames[i] = dbNames.get(i).asText();
}
*/
c.Result = res.Databases
return nil
}