MCPcopy Create free account
hub / github.com/ory/keto / parseHumanReadable

Function parseHumanReadable

cmd/relationtuple/parse.go:67–93  ·  view source on GitHub ↗

parseHumanReadable reads human-readable relation tuples from the reader. Input is limited to MaxFileSizeBytes.

(r io.Reader)

Source from the content-addressed store, hash-verified

65// parseHumanReadable reads human-readable relation tuples from the reader.
66// Input is limited to MaxFileSizeBytes.
67func parseHumanReadable(r io.Reader) ([]*ketoapi.RelationTuple, error) {
68 fc, err := io.ReadAll(io.LimitReader(r, int64(MaxFileSizeBytes)+1))
69 if err != nil {
70 return nil, fmt.Errorf("reading input: %w", err)
71 }
72 if len(fc) > MaxFileSizeBytes {
73 return nil, fmt.Errorf("input exceeds maximum size of %d bytes", MaxFileSizeBytes)
74 }
75
76 parts := strings.Split(string(fc), "\n")
77 rts := make([]*ketoapi.RelationTuple, 0, len(parts))
78 for i, row := range parts {
79 row = strings.TrimSpace(row)
80 // ignore comments and empty lines
81 if row == "" || strings.HasPrefix(row, "//") {
82 continue
83 }
84
85 rt, err := (&ketoapi.RelationTuple{}).FromString(row)
86 if err != nil {
87 return nil, fmt.Errorf("line %d: could not decode %q: %w", i+1, row, err)
88 }
89 rts = append(rts, rt)
90 }
91
92 return rts, nil
93}

Callers

nothing calls this directly

Calls 3

HasPrefixMethod · 0.80
ErrorfMethod · 0.45
FromStringMethod · 0.45

Tested by

no test coverage detected