ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/platform/samawards/client.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/platform/samawards/client.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberinternal/platform/samawards/client.go
Original SHA-25687a4ef7799217da34d06555fc2817b5087d05b7ac5f416622af900e9f94a49c1
Git blob SHA357a21f156e5ce9382f598f00f990456193a2e43
Reading-copy SHA-25687a4ef7799217da34d06555fc2817b5087d05b7ac5f416622af900e9f94a49c1

Original source ↗

Every recorded occurrence

These 31 records contain identical original source bytes. Their paths and revisions remain part of the archive.

Original recordBranch or archiveRevision / identifierOriginal location
Janady13/missionmatch / internal/platform/samawards/client.gofeature/opportunity-to-outcome720d47fae476b0d38477ae4401697d372b1ea2bcOpen original
Janady13/missionmatch / internal/platform/samawards/client.goper-tenant-routing9bde0f9a74b89d01980fa658e5253acda7528d0cOpen original
Janady13/missionmatch / internal/platform/samawards/client.gocollision-deconfliction4ee5a09972608ed89f8377c6665542d5f450f0a6Open original
Janady13/missionmatch / internal/platform/samawards/client.gows6-retrieval6c56e29231ec05735927fa265c97d517499dfeafOpen original
Janady13/missionmatch / internal/platform/samawards/client.goworkstream-a-shared-coree0de03ac3a1ec826bd15d0e048e3b02baa23eeffOpen original
Janady13/missionmatch / internal/platform/samawards/client.gom5-price-to-win41000ad30fff4129fdaf5ec84e15ba14c27d4890Open original
Janady13/missionmatch / internal/platform/samawards/client.goworkstream-c-slatematch5cd60c918301b46ecd6ed3e03e20c395da0062e2Open original
Janady13/missionmatch / internal/platform/samawards/client.gows1-ontology-syncb596f449a32a1016fbd403c36505cc00a1ac9ee6Open original
Janady13/missionmatch / internal/platform/samawards/client.gomaster1e9249840a4302ec82e123b9c9cb6f75badea3e4Open original
Janady13/missionmatch / internal/platform/samawards/client.gows8-teaching-loopc823f0fb6bb2aba0f39001eb6de96f4000d9321fOpen original
Janady13/missionmatch / internal/platform/samawards/client.gow3-ai-staffing-recommendations43d56387270ef4da4cabd794d97ca6a49909bc7dOpen original
Janady13/missionmatch / internal/platform/samawards/client.gomag-substrateb82c7100a492dec67dfd1eda6b3f53def859be35Open original
Janady13/missionmatch / internal/platform/samawards/client.gows3-clearance4b8e7ce594c068621867f9c9deed0ec64ae6c553Open original
Janady13/missionmatch / internal/platform/samawards/client.gophase2-eval-fairnessd361af254701975fe239927656ababb56374655eOpen original
Janady13/missionmatch / internal/platform/samawards/client.goworkstream-e-dataflow-deploy433815a042f9741411e60fa553fe72143e9b10dbOpen original
Janady13/missionmatch / internal/platform/samawards/client.goruthless-debug-sweepb7d742f8f032984be3817efffa3eb8b13b651c1fOpen original
Janady13/missionmatch / internal/platform/samawards/client.gotime-to-fill-survivalb66e1e505863d4f17741a4b9ede73509e45bd6c6Open original
Janady13/missionmatch / internal/platform/samawards/client.goai-intelligence-layer5d5ddff70393a197c5f54a45280bb5dd42b24755Open original
Janady13/missionmatch / internal/platform/samawards/client.gographrag-foundationb0ddeb9f633fd138d09309d1a17b7d13bc3a67f7Open original
Janady13/missionmatch / internal/platform/samawards/client.godeploy-and-opsbdacd9d0b4d5998d25fc74bf4007f4c3ec538c7aOpen original
Janady13/missionmatch / internal/platform/samawards/client.gows9-bench-ingestionf585a9ef32fa554663ce1fba9a414a54b6e49cf0Open original
Janady13/missionmatch / internal/platform/samawards/client.gows2-alias-relationshipe4dada4601c6eb101830f9d223a9655dfa120616Open original
Janady13/missionmatch / internal/platform/samawards/client.gopresentation-readinesseb574acaa29d71ce4d0f852572e87c275c79fdb7Open original
Janady13/missionmatch / internal/platform/samawards/client.govendor-intelligencefe9796a19c261951d3f2565206c0c1b5ac294465Open original
Janady13/missionmatch / internal/platform/samawards/client.goworkstream-b-screenmatch09015496d565a172bcaa15cfe9a8e4b072b13df0Open original
Janady13/missionmatch / internal/platform/samawards/client.gows7-federal-signal6a9f6ce9cfb13345ffb47770d4960e7c2d9c17c2Open original
Janady13/missionmatch / internal/platform/samawards/client.goai-brain-liveaac32fc49c878cc5bca099459307611562d0bac1Open original
Janady13/missionmatch / internal/platform/samawards/client.goworkstream-d-missionmatch3be46ba89edb737182075a2b320509b42dc916f8Open original
Janady13/missionmatch / internal/platform/samawards/client.gophase2-connectorse038d4c687aec16f8bd9bc4d907eea14d91f8704Open original
Janady13/missionmatch / internal/platform/samawards/client.gofeature/aioe-upgrade2178e7298d0e5d9af83afa12402fd587f0ba6ed8Open original
Janady13/missionmatch / internal/platform/samawards/client.gocapture-readinessbae6af7cb2997e819174a9e9cfff5e16067a1975Open original

Recovered source transcript

// Package samawards is a typed client for the SAM.gov Contract Awards API // (open.gsa.gov/api/contract-awards), the RESTful replacement for the retiring FPDS Atom feed. It // fetches federal contract award and incumbent data using the same SAM api_key the opportunities feed // uses, and normalizes it to a flat app shape. It has no database dependency: it fetches and // normalizes, the ingest writes the cache. The api_key is held here and only ever added as a query // parameter, never logged or placed in an error string. package samawards import ( "context" "encoding/json" "errors" "fmt" "io" "net/http" "net/url" "strconv" "strings" "time" ) // Base endpoints. Prod is the default; the alpha (prodlike) is selectable via the env for testing. const ( BaseProd = "https://api.sam.gov/contract-awards/v1/search" BaseAlpha = "https://api-alpha.sam.gov/contract-awards/v1/search" ) const ( maxLimit = 100 // the API caps a page at 100 offsetWindow = 400000 // offset times limit may not exceed this throttleCap = 1024 // max body bytes captured from a 429 pageGap = 250 * time.Millisecond ) // ErrThrottled is the sentinel for a 429 (daily quota). Detect with errors.Is(err, ErrThrottled). var ErrThrottled = errors.New("samawards: rate limited (429)") // ThrottleError carries the Retry-After hint. It satisfies errors.Is(err, ErrThrottled). type ThrottleError struct { RetryAfter string Body string } func (e *ThrottleError) Error() string { if e.RetryAfter != "" { return fmt.Sprintf("samawards: rate limited (429), retry after %s", e.RetryAfter) } return "samawards: rate limited (429)" } func (e *ThrottleError) Is(target error) bool { return target == ErrThrottled } // Client is a typed Contract Awards client over the built in net/http. type Client struct { base string key string http *http.Client } // New builds a client. An empty base defaults to prod. func New(base, key string) *Client { if strings.TrimSpace(base) == "" { base = BaseProd } return &Client{base: base, key: key, http: &http.Client{Timeout: 60 * time.Second}} } // SearchParams are the supported filters. NAICS is up to 100 codes (the API joins them with a tilde). // Department is a partial contracting department name (for example DEFENSE). AwardeeUEIs scopes to // specific recipients for own past performance. The Signed window filters by dateSigned. type SearchParams struct { NAICS []string Department string AwardeeUEIs []string SignedFrom time.Time SignedTo time.Time Limit int Offset int } // SearchResult is one page: the raw award records and the total match count the API reports. type SearchResult struct { Records []json.RawMessage Total int } // Search fetches one page. It maps a 429 to *ThrottleError and any other non 200 to an error that never // includes the api_key. func (c *Client) Search(ctx context.Context, p SearchParams) (SearchResult, error) { limit := p.Limit if limit < 1 { limit = 10 } if limit > maxLimit { limit = maxLimit } q := url.Values{} q.Set("api_key", c.key) q.Set("limit", strconv.Itoa(limit)) q.Set("offset", strconv.Itoa(p.Offset)) if len(p.NAICS) > 0 { q.Set("naicsCode", strings.Join(cap100(p.NAICS), "~")) } if d := strings.TrimSpace(p.Department); d != "" { q.Set("contractingDepartmentName", d) } if len(p.AwardeeUEIs) > 0 { q.Set("awardeeUniqueEntityId", strings.Join(cap100(p.AwardeeUEIs), "~")) } if !p.SignedFrom.IsZero() && !p.SignedTo.IsZero() { q.Set("dateSigned", fmt.Sprintf("[%s,%s]", p.SignedFrom.Format("01/02/2006"), p.SignedTo.Format("01/02/2006"))) } req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.base+"?"+q.Encode(), nil) if err != nil { // The error embeds the full URL including the api_key, so return a generic message. return SearchResult{}, errors.New("samawards: failed to build request") } req.Header.Set("Accept", "application/json") resp, err := c.http.Do(req) if err != nil { return SearchResult{}, fmt.Errorf("samawards: request: %w", err) } defer resp.Body.Close() if resp.StatusCode == http.StatusTooManyRequests { body, _ := io.ReadAll(io.LimitReader(resp.Body, throttleCap)) return SearchResult{}, &ThrottleError{RetryAfter: resp.Header.Get("Retry-After"), Body: string(body)} } if resp.StatusCode != http.StatusOK { body, _ := io.ReadAll(io.LimitReader(resp.Body, throttleCap)) return SearchResult{}, fmt.Errorf("samawards: status %d: %s", resp.StatusCode, strings.TrimSpace(string(body))) } var env struct { AwardSummary []json.RawMessage `json:"awardSummary"` TotalRecords NumericText `json:"totalRecords"` } if err := json.NewDecoder(resp.Body).Decode(&env); err != nil { return SearchResult{}, fmt.Errorf("samawards: decode: %w", err) } return SearchResult{Records: env.AwardSummary, Total: env.TotalRecords.Int()}, nil } // NumericText decodes a field the Contract Awards API returns inconsistently as either a JSON number or // a quoted string (totalRecords and the dollar amounts both arrive as strings) into the literal text, so // both forms parse the same way downstream. This was a real wire mismatch: the count and the dollars are // strings on the wire, which a plain int or json.Number field cannot decode. type NumericText string // UnmarshalJSON accepts a JSON number, a quoted string, or null. func (t *NumericText) UnmarshalJSON(b []byte) error { s := strings.TrimSpace(string(b)) if s == "null" { *t = "" return nil } *t = NumericText(strings.TrimSpace(strings.Trim(s, `"`))) return nil } // Int parses the text as an integer, tolerating a decimal point. It returns 0 when the text is empty or // unparseable, which for a record count safely stops pagination rather than looping. func (t NumericText) Int() int { s := string(t) if n, err := strconv.Atoi(s); err == nil { return n } if f, err := strconv.ParseFloat(s, 64); err == nil { return int(f) } return 0 } // SearchAll paginates by offset up to pageCap pages, stopping at the total or the API offset ceiling. On // a 429 it returns the records collected so far together with ErrThrottled so the caller keeps the // partial pull and stops gracefully. func (c *Client) SearchAll(ctx context.Context, p SearchParams, pageCap int) (recs []json.RawMessage, total int, capped bool, err error) { limit := p.Limit if limit < 1 { limit = maxLimit } if limit > maxLimit { limit = maxLimit } for page := 0; page < pageCap; page++ { pp := p pp.Limit = limit pp.Offset = page * limit if pp.Offset+limit > offsetWindow { capped = true break } res, e := c.Search(ctx, pp) if e != nil { if errors.Is(e, ErrThrottled) { return recs, total, true, ErrThrottled } return recs, total, capped, e } total = res.Total recs = append(recs, res.Records...) if len(res.Records) < limit || len(recs) >= total { return recs, total, capped, nil } select { case <-ctx.Done(): return recs, total, true, ctx.Err() case <-time.After(pageGap): } } if len(recs) < total { capped = true } return recs, total, capped, nil } // cap100 caps a slice to the API limit of 100 values per multi value parameter. func cap100(s []string) []string { if len(s) > 100 { return s[:100] } return s }

Search equations, builds, manuscript text, and recovered sources.