Refactored out detectFileMIMEType, matchesMIMEType logic for reuse. Added standalone isMIMEType validator for flexibility#1544
Open
dapzthelegend wants to merge 3 commits intogo-playground:masterfrom
Conversation
…dded standalone isMIMEType validator for flexibility
Author
|
PR #1 to refactor out the mime detection logic and create a flexible standalone isMIMEType Validator To keep existing behavior I've retained the type dict for isImage |
zemzale
previously approved these changes
Mar 18, 2026
Member
zemzale
left a comment
There was a problem hiding this comment.
One small tests thing, but the code looks good.
Would like someone else opinion about the validator itself, before merging.
validator_test.go
Outdated
| tag string | ||
| expected bool | ||
| createFile func() | ||
| destroyFile func() |
Member
There was a problem hiding this comment.
suggestion: You don't need this. Since you do t.Tempdir all the files are going to be deleted when the testrun ends.
The directory is automatically removed when the test and all its subtests complete
Author
There was a problem hiding this comment.
Just reviewed this and updated it, thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new built-in
mimetypevalidator for file paths.It supports both exact MIME matches and wildcard subtype matches:
Changes
mimetypeas a built-in validation tagisImageto reuse the shared MIME detection helperisImage's existing explicit image MIME allowlist unchangedmimetypemimetypeNotes
mimetypeaccepts:type/subtypetype/*Validation fails if the field is not a string, the file does not exist, the path is a directory, the MIME type cannot be detected, or the validator param is invalid.
Make sure that you've checked the boxes below before you submit PR:
@go-playground/validator-maintainers