mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-21 08:57:07 +08:00
35 lines
473 B
Go
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()
|
|
}
|