// FromJSONCompatibleMap constructs a Document-embedded struct from a JSON-compatible map.
FromJSONCompatibleMap constructs a Document-embedded struct from a JSON-compatible map.
// FromJSONCompatibleMap constructs a Document - embedded struct from a JSON - compatible map .
func FromJSONCompatibleMap(obj interface{}, docMap map[string]interface{}) error {
	ptrValue := reflect.ValueOf(obj)
	if ptrValue.Kind() != reflect.Ptr || ptrValue.Elem().Kind() != reflect.Struct {
		return ErrNotStruct
	}
	if ptrValue.Elem().FieldByName("Document") == zero {
		return ErrNotDocumentEmbedded
	}
	data, err := json.Marshal(docMap)
	if err != nil {
		return err
	}
	err = json.Unmarshal(data, obj)
	if err != nil {
		return err
	}
	if id, ok := docMap["_id"]; ok {
		setIDMethod := ptrValue.MethodByName("SetID")
		setIDMethod.Call([]reflect.Value{reflect.ValueOf(id)})
	}
	if rev, ok := docMap["_rev"]; ok {
		setRevMethod := ptrValue.MethodByName("SetRev")
		setRevMethod.Call([]reflect.Value{reflect.ValueOf(rev)})
	}
	return nil
}
func FromJSONCompatibleMap ( obj interface { } , docMap map [ string ] interface { } ) error { ptrValue := reflect . ValueOf ( obj ) if ptrValue . Kind ( ) != reflect . Ptr || ptrValue . Elem ( ) . Kind ( ) != reflect . Struct { return ErrNotStruct } if ptrValue . Elem ( ) . FieldByName ( " " ) == zero { return ErrNotDocumentEmbedded } data , err := json . Marshal ( docMap ) if err != nil { return err } err = json . Unmarshal ( data , obj ) if err != nil { return err } if id , ok := docMap [ " " ] ; ok { setIDMethod := ptrValue . MethodByName ( " " ) setIDMethod . Call ( [ ] reflect . Value { reflect . ValueOf ( id ) } ) } if rev , ok := docMap [ " " ] ; ok { setRevMethod := ptrValue . MethodByName ( " " ) setRevMethod . Call ( [ ] reflect . Value { reflect . ValueOf ( rev ) } ) } return nil }
FromJSONCompatibleMap constructs a Document-embedded struct from a JSON-compatible map.
FromJSONCompatibleMap constructs a Document - embedded struct from a JSON - compatible map .