package main import ( "fmt" "math/rand" "github.com/google/wire" ) type Rander interface { Rand() int } type DefaultRander struct{} func (r *DefaultRander) Rand() int { return rand.Int() //nolint:gosec } func NewRander() *DefaultRander { return &DefaultRander{} } type MockRander struct { Value int } func (r *MockRander) Rand() int { return r.Value } type Guess struct { rander Rander } func (g *Guess) Guess(guess int) string { return fmt.Sprintf("you guess %d, real number is %d", guess, g.rander.Rand()) } func NewGuess(rander Rander) *Guess { return &Guess{ rander: rander, } } type GuessWithMock struct { Guess *Guess Mock *MockRander } var GuessProviderSetWithoutMock = wire.NewSet(NewGuess) var GuessProviderSet = wire.NewSet( NewRander, NewGuess, wire.Bind(new(Rander), new(*DefaultRander)), ) var MockGuessProviderSet = wire.NewSet( wire.Struct(new(MockRander)), NewGuess, wire.Bind(new(Rander), new(*MockRander)), wire.Struct(new(GuessWithMock), "*"), )