| 427 | } |
| 428 | |
| 429 | func parseContentType(contentType string) (int, int, error) { |
| 430 | // Handle e.g. `application/json; charset=utf-8` or `my/format+json` |
| 431 | start := strings.IndexRune(contentType, '+') + 1 |
| 432 | end := strings.IndexRune(contentType, ';') |
| 433 | if end == -1 { |
| 434 | end = len(contentType) |
| 435 | } |
| 436 | |
| 437 | if end < start { |
| 438 | // This can happen if the `+` is after the `;`, which is not expected, |
| 439 | // but we should handle it gracefully. |
| 440 | return 0, 0, fmt.Errorf("%w: %s", ErrUnknownContentType, contentType) |
| 441 | } |
| 442 | |
| 443 | return start, end, nil |
| 444 | } |
| 445 | |
| 446 | // NewAPI creates a new API with the given configuration and router adapter. |
| 447 | // You usually don't need to use this function directly, and can instead use |