Skip to content

Commit

Permalink
Add missing type uint, uint8, uint16, uint32, uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
jneo8 committed Jul 15, 2020
1 parent 10207d1 commit 2fac6c8
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bind_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ func BindContainer(cfg *viper.Viper, container *dig.Container) error {
getter = func() []float64 {
return value
}
case uint:
getter = func() uint {
return cfg.GetUint(key)
}
case uint8:
getter = func() uint8 {
return value
}
case uint16:
getter = func() uint16 {
return value
}
case uint32:
getter = func() uint32 {
return cfg.GetUint32(key)
}
case uint64:
getter = func() uint64 {
return cfg.GetUint64(key)
}
case int: // count, int8, int16, int32
getter = func() int {
return cfg.GetInt(key)
Expand Down
80 changes: 80 additions & 0 deletions bind_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,86 @@ func TestBindContainer(t *testing.T) {
return err
},
},
{
name: "uint",
cfg: func() *viper.Viper {
cfg := setupViper()
cfg.SetDefault("v1", uint(1))
return cfg
}(),
exec: func(container *dig.Container) error {
type INPUT struct {
dig.In
V1 uint `name:"v1"`
}
err := container.Invoke(func(input INPUT) {})
return err
},
},
{
name: "uint8",
cfg: func() *viper.Viper {
cfg := setupViper()
cfg.SetDefault("v1", uint8(1))
return cfg
}(),
exec: func(container *dig.Container) error {
type INPUT struct {
dig.In
V1 uint8 `name:"v1"`
}
err := container.Invoke(func(input INPUT) {})
return err
},
},
{
name: "uint16",
cfg: func() *viper.Viper {
cfg := setupViper()
cfg.SetDefault("v1", uint16(1))
return cfg
}(),
exec: func(container *dig.Container) error {
type INPUT struct {
dig.In
V1 uint16 `name:"v1"`
}
err := container.Invoke(func(input INPUT) {})
return err
},
},
{
name: "uint32",
cfg: func() *viper.Viper {
cfg := setupViper()
cfg.SetDefault("v1", uint32(1))
return cfg
}(),
exec: func(container *dig.Container) error {
type INPUT struct {
dig.In
V1 uint32 `name:"v1"`
}
err := container.Invoke(func(input INPUT) {})
return err
},
},
{
name: "uint64",
cfg: func() *viper.Viper {
cfg := setupViper()
cfg.SetDefault("v1", uint64(1))
return cfg
}(),
exec: func(container *dig.Container) error {
type INPUT struct {
dig.In
V1 uint64 `name:"v1"`
}
err := container.Invoke(func(input INPUT) {})
return err
},
},
{
name: "intSlice",
cfg: func() *viper.Viper {
Expand Down

0 comments on commit 2fac6c8

Please sign in to comment.