github.com/altipla-consulting/ravendb-go-client@v0.1.3/next_identity_for_command.go (about) 1 package ravendb 2 3 import ( 4 "net/http" 5 ) 6 7 var ( 8 _ RavenCommand = &NextIdentityForCommand{} 9 ) 10 11 type NextIdentityForCommand struct { 12 RavenCommandBase 13 14 _id string 15 16 Result int 17 } 18 19 func NewNextIdentityForCommand(id string) *NextIdentityForCommand { 20 res := &NextIdentityForCommand{ 21 RavenCommandBase: NewRavenCommandBase(), 22 23 _id: id, 24 } 25 panicIf(id == "", "Id cannot be null") 26 27 return res 28 } 29 30 func (c *NextIdentityForCommand) createRequest(node *ServerNode) (*http.Request, error) { 31 err := ensureIsNotNullOrString(c._id, "ID") 32 if err != nil { 33 return nil, err 34 } 35 36 url := node.URL + "/databases/" + node.Database + "/identity/next?name=" + urlEncode(c._id) 37 38 return newHttpPost(url, nil) 39 } 40 41 func (c *NextIdentityForCommand) setResponse(response []byte, fromCache bool) error { 42 if len(response) == 0 { 43 return throwInvalidResponse() 44 } 45 var jsonNode map[string]interface{} 46 err := jsonUnmarshal(response, &jsonNode) 47 if err != nil { 48 return err 49 } 50 n, ok := jsonGetAsInt(jsonNode, "NewIdentityValue") 51 if !ok { 52 return throwInvalidResponse() 53 } 54 c.Result = n 55 return nil 56 }