| 528 | } |
| 529 | |
| 530 | func parseGeneratedFieldTagID(structTag string) (int, bool, error) { |
| 531 | if structTag == "" { |
| 532 | return 0, false, nil |
| 533 | } |
| 534 | foryTag, ok := reflect.StructTag(structTag).Lookup("fory") |
| 535 | if !ok || foryTag == "-" { |
| 536 | return 0, false, nil |
| 537 | } |
| 538 | tagID := 0 |
| 539 | seenID := false |
| 540 | for _, part := range strings.Split(foryTag, ",") { |
| 541 | part = strings.TrimSpace(part) |
| 542 | if part == "id" { |
| 543 | return 0, false, fmt.Errorf("field id requires a value") |
| 544 | } |
| 545 | idText, ok := strings.CutPrefix(part, "id=") |
| 546 | if !ok { |
| 547 | continue |
| 548 | } |
| 549 | if seenID { |
| 550 | return 0, false, fmt.Errorf("duplicate field id tag") |
| 551 | } |
| 552 | seenID = true |
| 553 | parsedTagID, err := strconv.Atoi(idText) |
| 554 | if err != nil { |
| 555 | return 0, false, fmt.Errorf("invalid field id %q", idText) |
| 556 | } |
| 557 | if parsedTagID < 0 { |
| 558 | return 0, false, fmt.Errorf("field id must be non-negative") |
| 559 | } |
| 560 | tagID = parsedTagID |
| 561 | } |
| 562 | return tagID, seenID, nil |
| 563 | } |