(orefStr string)
| 78 | var otypeRe = regexp.MustCompile(`^[a-z]+$`) |
| 79 | |
| 80 | func ParseORef(orefStr string) (ORef, error) { |
| 81 | fields := strings.Split(orefStr, ":") |
| 82 | if len(fields) != 2 { |
| 83 | return ORef{}, fmt.Errorf("invalid object reference: %q", orefStr) |
| 84 | } |
| 85 | otype := fields[0] |
| 86 | if !otypeRe.MatchString(otype) { |
| 87 | return ORef{}, fmt.Errorf("invalid object type: %q", otype) |
| 88 | } |
| 89 | if !ValidOTypes[otype] { |
| 90 | return ORef{}, fmt.Errorf("unknown object type: %q", otype) |
| 91 | } |
| 92 | oid := fields[1] |
| 93 | _, err := uuid.Parse(oid) |
| 94 | if err != nil { |
| 95 | return ORef{}, fmt.Errorf("invalid object id: %q", oid) |
| 96 | } |
| 97 | return ORef{OType: otype, OID: oid}, nil |
| 98 | } |
| 99 | |
| 100 | func ParseORefNoErr(orefStr string) *ORef { |
| 101 | oref, err := ParseORef(orefStr) |
no test coverage detected