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

Function ParseUUIDList

coderd/util/xjson/xjson.go:15–35  ·  view source on GitHub ↗

ParseUUIDList parses a JSON-encoded array of UUID strings (e.g. `["uuid1","uuid2"]`) and returns the corresponding slice of uuid.UUID values. An empty input (including whitespace-only) returns an empty (non-nil) slice.

(raw string)

Source from the content-addressed store, hash-verified

13// slice of uuid.UUID values. An empty input (including
14// whitespace-only) returns an empty (non-nil) slice.
15func ParseUUIDList(raw string) ([]uuid.UUID, error) {
16 raw = strings.TrimSpace(raw)
17 if raw == "" {
18 return []uuid.UUID{}, nil
19 }
20
21 var strs []string
22 if err := json.Unmarshal([]byte(raw), &strs); err != nil {
23 return nil, xerrors.Errorf("unmarshal uuid list: %w", err)
24 }
25
26 ids := make([]uuid.UUID, 0, len(strs))
27 for _, s := range strs {
28 id, err := uuid.Parse(s)
29 if err != nil {
30 return nil, xerrors.Errorf("parse uuid %q: %w", s, err)
31 }
32 ids = append(ids, id)
33 }
34 return ids, nil
35}

Callers 3

chatTemplateAllowlistMethod · 0.92
TestParseUUIDListFunction · 0.92

Calls 3

ParseMethod · 0.65
UnmarshalMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestParseUUIDListFunction · 0.74