MCPcopy Create free account
hub / github.com/cli/cli / readJSONL

Function readJSONL

script/ghmock/store.go:251–272  ·  view source on GitHub ↗

readJSONL reads a file of JSON objects, one per line. A missing file has none.

(path string)

Source from the content-addressed store, hash-verified

249// readJSONL reads a file of JSON objects, one per line. A missing file has
250// none.
251func readJSONL[T any](path string) ([]T, error) {
252 f, err := os.Open(path)
253 if errors.Is(err, fs.ErrNotExist) {
254 return nil, nil
255 }
256 if err != nil {
257 return nil, err
258 }
259 defer f.Close()
260
261 var items []T
262 decoder := json.NewDecoder(f)
263 for {
264 var item T
265 if err := decoder.Decode(&item); errors.Is(err, io.EOF) {
266 return items, nil
267 } else if err != nil {
268 return nil, fmt.Errorf("reading %s: %w", path, err)
269 }
270 items = append(items, item)
271 }
272}
273
274func (s *state) reset() error {
275 for _, p := range []string{s.responsesPath(), s.logPath(), s.runsPath()} {

Callers

nothing calls this directly

Calls 3

OpenMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected