| 8 | ) |
| 9 | |
| 10 | func ParseID(s string) (ksuid.KSUID, error) { |
| 11 | // Check if this is a cut-and-paste from BSUP, which encodes |
| 12 | // the 20-byte KSUID as a 40 character hex string with 0x prefix. |
| 13 | var id ksuid.KSUID |
| 14 | var err error |
| 15 | if len(s) == 42 && s[0:2] == "0x" { |
| 16 | var b []byte |
| 17 | b, err = hex.DecodeString(s[2:]) |
| 18 | if err == nil { |
| 19 | id, err = ksuid.FromBytes(b) |
| 20 | } |
| 21 | } else { |
| 22 | id, err = ksuid.Parse(s) |
| 23 | } |
| 24 | if err != nil { |
| 25 | return ksuid.Nil, fmt.Errorf("invalid ID: %s", s) |
| 26 | } |
| 27 | return id, nil |
| 28 | } |
| 29 | |
| 30 | func ParseIDs(ss []string) ([]ksuid.KSUID, error) { |
| 31 | ids := make([]ksuid.KSUID, 0, len(ss)) |