Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (45 sloc) 1.28 KB
package ravendb
import (
"reflect"
)
// CompareExchangeResult describes result of compare exchange
type CompareExchangeResult struct {
Value interface{}
Index int64
IsSuccessful bool
}
func parseCompareExchangeResultFromString(clazz reflect.Type, responseString []byte, conventions *DocumentConventions) (*CompareExchangeResult, error) {
var response map[string]interface{}
err := jsonUnmarshal(responseString, &response)
if err != nil {
return nil, err
}
index, ok := jsonGetAsInt64(response, "Index")
if !ok {
return nil, newIllegalStateError("Response is invalid. Index is missing")
}
successful, _ := jsonGetAsBool(response, "Successful")
var val interface{}
raw, ok := response["Value"]
if ok && raw != nil {
if m, ok := raw.(map[string]interface{}); ok {
val = m["Object"]
}
}
if val == nil {
exchangeResult := &CompareExchangeResult{}
exchangeResult.Index = index
exchangeResult.Value = getDefaultValueForType(clazz)
exchangeResult.IsSuccessful = successful
return exchangeResult, nil
}
result, err := convertValue(val, clazz)
if err != nil {
return nil, err
}
exchangeResult := &CompareExchangeResult{}
exchangeResult.Index = index
exchangeResult.Value = result
exchangeResult.IsSuccessful = successful
return exchangeResult, nil
}
You can’t perform that action at this time.