package broker import ( "errors" "local/truckstop/config" "net/http" ) type FastExact struct { doer interface { doRequest(*http.Request) (*http.Response, error) } } func NewFastExact() FastExact { fe := FastExact{} fe.doer = fe return fe } func (fe FastExact) WithMock() FastExact { fe.doer = mockFastExactDoer{} return fe } func (fe FastExact) Search(states []config.State) ([]Job, error) { jobs, err := fe.search(states) if err == ErrNoAuth { if err := fe.login(); err != nil { return nil, err } jobs, err = fe.search(states) } return jobs, err } func (fe FastExact) login() error { return errors.New("not impl") } func (fe FastExact) search(states []config.State) ([]Job, error) { req, err := fe.newRequest(states) if err != nil { return nil, err } resp, err := fe.doRequest(req) if err != nil { return nil, err } return fe.parse(resp) } func (fe FastExact) newRequest(states []config.State) (*http.Request, error) { return nil, errors.New("not impl") } func (fe FastExact) doRequest(req *http.Request) (*http.Response, error) { return nil, errors.New("not impl") } func (fe FastExact) parse(resp *http.Response) ([]Job, error) { return nil, errors.New("not impl") } type mockFastExactDoer struct{} func (mock mockFastExactDoer) doRequest(*http.Request) (*http.Response, error) { return nil, errors.New("not impl") }