MCPcopy Create free account
hub / github.com/Hidden-Node/GooseRelayVPN-AndroidClient / fetchScriptStats

Method fetchScriptStats

internal/carrier/quota.go:146–174  ·  view source on GitHub ↗
(ctx context.Context, idx int, url string)

Source from the content-addressed store, hash-verified

144}
145
146func (c *Client) fetchScriptStats(ctx context.Context, idx int, url string) {
147 reqCtx, cancel := context.WithTimeout(ctx, scriptStatsRequestTimeout)
148 defer cancel()
149 req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, url, nil)
150 if err != nil {
151 return
152 }
153 resp, err := c.pickHTTPClient().Do(req)
154 if err != nil {
155 // Transport error — don't bump the daily count (request never reached
156 // Apps Script) and don't log; the next interval will retry.
157 return
158 }
159 defer resp.Body.Close()
160
161 body, readErr := io.ReadAll(io.LimitReader(resp.Body, scriptStatsMaxBody))
162 // doGet, like doPost, consumes one Apps Script invocation regardless of
163 // what we do with the response, so bump the daily counter on any HTTP
164 // response we got back.
165 c.bumpDailyCount(idx)
166 if readErr != nil {
167 return
168 }
169
170 if resp.StatusCode != http.StatusOK {
171 return
172 }
173 c.recordScriptStatsFromBody(idx, url, body)
174}
175
176// recordScriptStatsFromBody parses a doGet response body and stores the count.
177// Split out from fetchScriptStats so the parsing logic is unit-testable without

Callers 1

pollScriptStatsMethod · 0.95

Calls 4

pickHTTPClientMethod · 0.95
bumpDailyCountMethod · 0.95
CloseMethod · 0.80

Tested by

no test coverage detected