MCPcopy Index your code
hub / github.com/coder/coder / fetch

Function fetch

scripts/aibridgepricesgen/main.go:108–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106}
107
108func fetch() (map[string]upstreamProvider, error) {
109 ctx, cancel := context.WithTimeout(context.Background(), fetchTimeout)
110 defer cancel()
111
112 req, err := http.NewRequestWithContext(ctx, http.MethodGet, sourceURL, nil)
113 if err != nil {
114 return nil, err
115 }
116 resp, err := http.DefaultClient.Do(req)
117 if err != nil {
118 return nil, err
119 }
120 defer resp.Body.Close()
121 if resp.StatusCode != http.StatusOK {
122 return nil, xerrors.Errorf("status %d", resp.StatusCode)
123 }
124
125 var data map[string]upstreamProvider
126 if err := json.NewDecoder(io.LimitReader(resp.Body, maxBodyBytes)).Decode(&data); err != nil {
127 return nil, xerrors.Errorf("parse: %w", err)
128 }
129 return data, nil
130}
131
132// convert flattens the upstream map into table-shaped rows for the configured
133// providers. If any configured provider is absent from the upstream payload,

Callers 6

runFunction · 0.70
probeAttachmentFailureFunction · 0.50
beginUploadFunction · 0.50
startUploadFunction · 0.50

Calls 3

DoMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected