(input any)
| 30 | } |
| 31 | |
| 32 | func parseReadTextFileInput(input any) (*readTextFileParams, error) { |
| 33 | result := &readTextFileParams{} |
| 34 | |
| 35 | if input == nil { |
| 36 | return nil, fmt.Errorf("input is required") |
| 37 | } |
| 38 | |
| 39 | if err := utilfn.ReUnmarshal(result, input); err != nil { |
| 40 | return nil, fmt.Errorf("invalid input format: %w", err) |
| 41 | } |
| 42 | |
| 43 | if result.Filename == "" { |
| 44 | return nil, fmt.Errorf("missing filename parameter") |
| 45 | } |
| 46 | |
| 47 | if result.Origin == nil { |
| 48 | origin := "start" |
| 49 | result.Origin = &origin |
| 50 | } |
| 51 | |
| 52 | if *result.Origin != "start" && *result.Origin != "end" { |
| 53 | return nil, fmt.Errorf("invalid origin value '%s': must be 'start' or 'end'", *result.Origin) |
| 54 | } |
| 55 | |
| 56 | if result.Offset == nil { |
| 57 | offset := 0 |
| 58 | result.Offset = &offset |
| 59 | } |
| 60 | |
| 61 | if *result.Offset < 0 { |
| 62 | return nil, fmt.Errorf("offset must be non-negative, got %d", *result.Offset) |
| 63 | } |
| 64 | |
| 65 | if result.Count == nil { |
| 66 | count := ReadFileDefaultLineCount |
| 67 | result.Count = &count |
| 68 | } |
| 69 | |
| 70 | if *result.Count < 1 { |
| 71 | return nil, fmt.Errorf("count must be at least 1, got %d", *result.Count) |
| 72 | } |
| 73 | |
| 74 | if result.MaxBytes == nil { |
| 75 | maxBytes := ReadFileDefaultMaxBytes |
| 76 | result.MaxBytes = &maxBytes |
| 77 | } |
| 78 | |
| 79 | return result, nil |
| 80 | } |
| 81 | |
| 82 | // truncateData truncates data to maxBytes while respecting line boundaries. |
| 83 | // For origin "start", keeps the beginning and truncates at last newline before maxBytes. |
no test coverage detected