Skip to content

Commit

Permalink
ovsdb: unexport GoSet struct field
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Williams <[email protected]>
  • Loading branch information
dcbw committed Sep 15, 2022
1 parent c915188 commit f71dfa8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ovsdb/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}
}
34 changes: 17 additions & 17 deletions ovsdb/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// values in the set. All of the <atom>s must have the same type, and all
// values must be unique within the set.
type OvsSet struct {
GoSet []interface{}
goSet []interface{}
maxSize int
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -99,35 +99,35 @@ 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
}

// 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
}
Expand Down Expand Up @@ -166,41 +166,41 @@ 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
}

// HasElementType matches the given value's type with the set's element type.
// 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
// each element. The function should return true if iteration should terminate,
// 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
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/updates2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f71dfa8

Please sign in to comment.