github.com/altipla-consulting/ravendb-go-client@v0.1.3/create_subscription_command.go (about) 1 package ravendb 2 3 import ( 4 "encoding/json" 5 "net/http" 6 ) 7 8 var ( 9 _ RavenCommand = &CreateSubscriptionCommand{} 10 ) 11 12 // CreateSubscriptionCommand represents "create subscription" command 13 type CreateSubscriptionCommand struct { 14 RavenCommandBase 15 16 conventions *DocumentConventions 17 options *SubscriptionCreationOptions 18 id string 19 20 Result *CreateSubscriptionResult 21 } 22 23 func newCreateSubscriptionCommand(conventions *DocumentConventions, options *SubscriptionCreationOptions, id string) *CreateSubscriptionCommand { 24 return &CreateSubscriptionCommand{ 25 RavenCommandBase: NewRavenCommandBase(), 26 27 conventions: conventions, 28 options: options, 29 id: id, 30 } 31 } 32 33 func (c *CreateSubscriptionCommand) createRequest(node *ServerNode) (*http.Request, error) { 34 uri := node.URL + "/databases/" + node.Database + "/subscriptions" 35 36 if c.id != "" { 37 uri += "?id=" + c.id 38 } 39 40 d, err := json.Marshal(c.options) 41 if err != nil { 42 return nil, err 43 } 44 45 return newHttpPut(uri, d) 46 } 47 48 func (c *CreateSubscriptionCommand) setResponse(response []byte, fromCache bool) error { 49 if len(response) == 0 { 50 return throwInvalidResponse() 51 } 52 return jsonUnmarshal(response, &c.Result) 53 }