diff --git a/ovsdb/bindings.go b/ovsdb/bindings.go index 82c34e03..e75648d2 100644 --- a/ovsdb/bindings.go +++ b/ovsdb/bindings.go @@ -162,7 +162,7 @@ func OvsToNative(column *ColumnSchema, ovsElem interface{}) (interface{}, error) } else if ovsSet.Len() == 0 { return reflect.Zero(naType).Interface(), nil } - native, err := OvsToNativeAtomic(column.TypeObj.Key.Type, ovsSet.GoSet[0]) + native, err := OvsToNativeAtomic(column.TypeObj.Key.Type, ovsSet.goSet[0]) if err != nil { return nil, err } diff --git a/ovsdb/encoding_test.go b/ovsdb/encoding_test.go index fc537574..2b7a565c 100644 --- a/ovsdb/encoding_test.go +++ b/ovsdb/encoding_test.go @@ -193,7 +193,7 @@ func TestSet(t *testing.T) { var res OvsSet err = json.Unmarshal(jsonStr, &res) assert.Nil(t, err) - assert.Equal(t, set.GoSet, res.GoSet, "they should have the same elements\n") + assert.Equal(t, set.goSet, res.goSet, "they should have the same elements\n") }) } } diff --git a/ovsdb/set.go b/ovsdb/set.go index f1074f2c..a5177689 100644 --- a/ovsdb/set.go +++ b/ovsdb/set.go @@ -15,7 +15,7 @@ import ( // values in the set. All of the s must have the same type, and all // values must be unique within the set. type OvsSet struct { - GoSet []interface{} + goSet []interface{} maxSize int } @@ -51,7 +51,7 @@ func newOvsSetRaw(keyType string, maxSizePtr *int, obj interface{}) (OvsSet, err if v.Kind() == reflect.Invalid { // must be a nil pointer, so just return an empty set return OvsSet{ - GoSet: ovsSet, + goSet: ovsSet, maxSize: maxSize, }, nil } @@ -99,20 +99,20 @@ func newOvsSetRaw(keyType string, maxSizePtr *int, obj interface{}) (OvsSet, err return OvsSet{}, fmt.Errorf("ovsset supports only go slice/string/numbers/uuid or pointers to those types") } return OvsSet{ - GoSet: ovsSet, + goSet: ovsSet, maxSize: maxSize, }, nil } // MarshalJSON wil marshal an OVSDB style Set in to a JSON byte array func (o OvsSet) MarshalJSON() ([]byte, error) { - switch l := len(o.GoSet); { + switch l := len(o.goSet); { case l == 1: - return json.Marshal(o.GoSet[0]) + return json.Marshal(o.goSet[0]) case l > 0: var oSet []interface{} oSet = append(oSet, "set") - oSet = append(oSet, o.GoSet) + oSet = append(oSet, o.goSet) return json.Marshal(oSet) } return []byte("[\"set\",[]]"), nil @@ -120,14 +120,14 @@ func (o OvsSet) MarshalJSON() ([]byte, error) { // UnmarshalJSON will unmarshal a JSON byte array to an OVSDB style Set func (o *OvsSet) UnmarshalJSON(b []byte) (err error) { - o.GoSet = make([]interface{}, 0) + o.goSet = make([]interface{}, 0) if o.maxSize == 0 { o.maxSize = Unlimited } addToSet := func(o *OvsSet, v interface{}) error { goVal, err := ovsSliceToGoNotation(v) if err == nil { - o.GoSet = append(o.GoSet, goVal) + o.goSet = append(o.goSet, goVal) } return err } @@ -166,22 +166,22 @@ func (o *OvsSet) UnmarshalJSON(b []byte) (err error) { } func (o *OvsSet) Append(newVal ...interface{}) error { - if o.maxSize > 0 && len(o.GoSet)+len(newVal) > o.maxSize { + if o.maxSize > 0 && len(o.goSet)+len(newVal) > o.maxSize { return fmt.Errorf("appending new value would exceed max set size %d", o.maxSize) } - o.GoSet = append(o.GoSet, newVal...) + o.goSet = append(o.goSet, newVal...) return nil } func (o *OvsSet) Len() int { - return len(o.GoSet) + return len(o.goSet) } func (o *OvsSet) Replace(idx int, newVal interface{}) error { - if idx > len(o.GoSet)-1 { - return fmt.Errorf("attempted to access element %d beyond end of array (length %d)", idx, len(o.GoSet)) + if idx > len(o.goSet)-1 { + return fmt.Errorf("attempted to access element %d beyond end of array (length %d)", idx, len(o.goSet)) } - o.GoSet[idx] = newVal + o.goSet[idx] = newVal return nil } @@ -189,10 +189,10 @@ func (o *OvsSet) Replace(idx int, newVal interface{}) error { // It returns true if the set has at least one element, and that element is // of the given type, otherwise false. func (o *OvsSet) HasElementType(checkVal interface{}) bool { - if len(o.GoSet) == 0 { + if len(o.goSet) == 0 { return false } - return reflect.ValueOf(checkVal).Type() == reflect.ValueOf(o.GoSet[0]).Type() + return reflect.ValueOf(checkVal).Type() == reflect.ValueOf(o.goSet[0]).Type() } // Range iterates over elements of the set and calls the given function for @@ -200,7 +200,7 @@ func (o *OvsSet) HasElementType(checkVal interface{}) bool { // a value to return to the caller of Range(), and/or an error (which also // terminates iteration). func (o *OvsSet) Range(elemFn func(int, interface{}) (bool, error)) error { - for i, v := range o.GoSet { + for i, v := range o.goSet { done, err := elemFn(i, v) if err != nil { return err diff --git a/ovsdb/updates2.go b/ovsdb/updates2.go index b994fc75..9e85f610 100644 --- a/ovsdb/updates2.go +++ b/ovsdb/updates2.go @@ -82,7 +82,7 @@ func (r *RowUpdate2) Merge(new *RowUpdate2) error { case OvsSet: oSet := currentRowData[k].(OvsSet) newSet := v.(OvsSet) - if err := oSet.Append(newSet.GoSet...); err != nil { + if err := oSet.Append(newSet.goSet...); err != nil { return err } // copy new appended set back to currentRowData