Files
job-search/internal/findATender/findATender.go
T
bwilliams 399eccf2de Find a Tender API client updates
- Convert OCDS releases to types.Opportunity (internal/types); FetchOnce
  and FetchAll now return opportunities, built from each ocid's latest
  release
- Include each item's main classification as well as its additional ones
- Return ErrUnexpectedStatus for non-200 responses and
  ErrRateLimitExceeded for a repeated 429; close discarded bodies
- Stop fetchAll on a repeated next link and close each page's body once
  read rather than deferring in the loop
- Default a zero Since to 24 hours ago
- Merge date repair and releaseIDs into api.go
- Filter --planning/--opportunities/--awards on each procedure's current
  stage, using OCDS release tags; --opportunities previously matched a
  nonexistent "opportunity" tag and returned nothing
- Reject conflicting filters before fetching (cobra flag group)
2026-10-09 17:56:55 +01:00

75 lines
1.4 KiB
Go

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
}