github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/serverwide/operations/operation_add_cluster_node.go (about) 1 package operations 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "github.com/ravendb/ravendb-go-client" 7 "net/http" 8 "net/url" 9 "strconv" 10 "strings" 11 ) 12 13 type OperationAddClusterNode struct { 14 Url string `json:"Url"` 15 Tag string `json:"Tag"` 16 Watcher bool `json:"Watcher"` 17 } 18 19 func (operation *OperationAddClusterNode) GetCommand(conventions *ravendb.DocumentConventions) (ravendb.RavenCommand, error) { 20 return &addNodeCommand{ 21 RaftCommandBase: ravendb.RaftCommandBase{ 22 RavenCommandBase: ravendb.RavenCommandBase{ 23 ResponseType: ravendb.RavenCommandResponseTypeObject, 24 }, 25 }, 26 parent: operation, 27 }, nil 28 } 29 30 type addNodeCommand struct { 31 ravendb.RaftCommandBase 32 parent *OperationAddClusterNode 33 } 34 35 func (c *addNodeCommand) CreateRequest(node *ravendb.ServerNode) (*http.Request, error) { 36 url := node.URL + "/admin/cluster/node?url=" + url.QueryEscape(c.parent.Url) + "&watcher=" + strconv.FormatBool(c.parent.Watcher) 37 38 if len(strings.TrimSpace(c.parent.Tag)) == 0 { 39 url += fmt.Sprintf("&tag=%s", c.parent.Tag) 40 } 41 return http.NewRequest(http.MethodPut, url, nil) 42 } 43 44 func (c *addNodeCommand) SetResponse(response []byte, fromCache bool) error { 45 return json.Unmarshal(response, c.parent) 46 }