package findATender import ( "context" "time" "git.avsdev.uk/Go/job-search/internal/config" "git.avsdev.uk/Go/job-search/internal/types" resty "resty.dev/v3" ) type FindATender struct { httpClient *resty.Client config *config.JobSearchConfig apiRoot string ctx context.Context } func New(conf *config.JobSearchConfig, apiRoot string) FindATender { ft := FindATender{ config: conf, apiRoot: apiRoot, } ft.httpClient = resty.New(). SetTimeout(60 * time.Duration(time.Second)). SetRetryCount(1) return ft } func (ft *FindATender) ReloadConfig(conf *config.JobSearchConfig) { ft.config = conf } func (ft *FindATender) With(ctx context.Context) *FindATender { if ctx == nil { return ft } copied := *ft copied.ctx = ctx return &copied } func (ft *FindATender) Shutdown() { ft.httpClient.Close() } func (ft *FindATender) FetchOnce( since time.Time, allowRateLimit bool, ) ([]*types.Opportunity, error) { releases, err := ft.fetchOnce(RequestOptions{ Since: since, AllowRateLimit: allowRateLimit, }) if err != nil { return nil, err } return Convert(releases), nil } func (ft *FindATender) FetchAll( since time.Time, allowRateLimit bool, ) ([]*types.Opportunity, error) { releases, err := ft.fetchAll(RequestOptions{ Since: since, AllowRateLimit: allowRateLimit, }) if err != nil { return nil, err } return Convert(releases), nil }