100-go-mistakes/02-code-project-organization/5-interface-pollution/restricting-behavior/main.go
2022-01-27 00:06:23 +01:00

35 lines
473 B
Go

package main
type IntConfig struct {
value int
}
func (c *IntConfig) Get() int {
return c.value
}
func (c *IntConfig) Set(value int) {
c.value = value
}
type intConfigGetter interface {
Get() int
}
type Foo struct {
threshold intConfigGetter
}
func NewFoo(threshold intConfigGetter) Foo {
return Foo{threshold: threshold}
}
func (f Foo) Bar() {
threshold := f.threshold.Get()
_ = threshold
}
func main() {
foo := NewFoo(&IntConfig{value: 42})
foo.Bar()
}