Skip to content

Commit

Permalink
Renamed custom type to user defined type
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed Dec 7, 2016
1 parent 4ee4eed commit 1730c1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions config/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ func (cv Value) valueStruct(key string, target interface{}) (interface{}, error)
fieldValue.Set(reflect.New(fieldType.Elem()))
}

// We cannot assign reflect.ValueOf(val) to fieldValue as is, when field is a custom type
// We cannot assign reflect.ValueOf(val) to fieldValue as is, when field is a user defined type
// We need to find the Kind of the custom type and set the fieldValue to the specific type
// that custom type is defined with.
// that user defined type is defined with.
kind := fieldType.Elem().Kind()
switch kind {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
Expand Down
6 changes: 3 additions & 3 deletions config/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ func TestTypeOfTypes(t *testing.T) {
tts := typeStructStruct{}
err := provider.Get("").PopulateStruct(&tts)
assert.NoError(t, err)
assert.Equal(t, customTypeInt(123), *tts.TypeStruct.TestInt)
assert.Equal(t, customTypeUInt(456), *tts.TypeStruct.TestUInt)
assert.Equal(t, customTypeFloat(123.456), *tts.TypeStruct.TestFloat)
assert.Equal(t, userDefinedTypeInt(123), *tts.TypeStruct.TestInt)
assert.Equal(t, userDefinedTypeUInt(456), *tts.TypeStruct.TestUInt)
assert.Equal(t, userDefinedTypeFloat(123.456), *tts.TypeStruct.TestFloat)
})
}
12 changes: 6 additions & 6 deletions config/yaml_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ mapStruct:
additionalData: nesteddata
`)

type customTypeInt nestedTypeInt
type userDefinedTypeInt nestedTypeInt
type nestedTypeInt int64

type customTypeUInt nestedTypeUInt
type userDefinedTypeUInt nestedTypeUInt
type nestedTypeUInt uint32

type customTypeFloat nestedTypeFloat
type userDefinedTypeFloat nestedTypeFloat
type nestedTypeFloat float32

type nestedTypeStruct struct {
TestInt *customTypeInt `yaml:"testInt"`
TestUInt *customTypeUInt `yaml:"testUInt"`
TestFloat *customTypeFloat `yaml:"testFloat"`
TestInt *userDefinedTypeInt `yaml:"testInt"`
TestUInt *userDefinedTypeUInt `yaml:"testUInt"`
TestFloat *userDefinedTypeFloat `yaml:"testFloat"`
}

type typeStruct nestedTypeStruct
Expand Down
5 changes: 5 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
// performant services at Uber with the minimum amount of developer code.
//
//
// Examples
//
// To get a feel for what an UberFx service looks like, see our
// examples (examples/).
//
// Service Model
//
// A service is a container for a set of **modules**, controlling their lifecycle.
Expand Down

0 comments on commit 1730c1e

Please sign in to comment.