Skip to content

feat: add audio validation#1539

Open
dapzthelegend wants to merge 4 commits into
go-playground:masterfrom
dapzthelegend:feature/audio-validation
Open

feat: add audio validation#1539
dapzthelegend wants to merge 4 commits into
go-playground:masterfrom
dapzthelegend:feature/audio-validation

Conversation

@dapzthelegend
Copy link
Copy Markdown
Contributor

@dapzthelegend dapzthelegend commented Mar 9, 2026

Fixes Or Enhances

Adds built-in audio validation tag support via a new isAudio validator.

isAudio implementation

// isAudio is the validation function for validating if the current field's value contains the path to a valid audio file
func isAudio(fl FieldLevel) bool {
	mime, ok := detectFileMIMEType(fl.Field())
	if !ok {
		return false
	}

	return strings.HasPrefix(mime, "audio/")
}

Example Usage

package main

import (
	"fmt"

	"github.com/go-playground/validator/v10"
)

type Upload struct {
	AudioPath string `validate:"required,audio"`
}

func main() {
	validate := validator.New()

	u := Upload{AudioPath: "testdata/music.mp3"}
	if err := validate.Struct(u); err != nil {
		fmt.Println("validation failed:", err)
		return
	}

	fmt.Println("validation passed")
}

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@dapzthelegend dapzthelegend requested a review from a team as a code owner March 9, 2026 23:12
@dapzthelegend
Copy link
Copy Markdown
Contributor Author

@the-fanan

@the-fanan
Copy link
Copy Markdown
Contributor

Looks good to me. Let's ship this please!

zemzale
zemzale previously approved these changes Mar 11, 2026
Copy link
Copy Markdown
Member

@zemzale zemzale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small thing that could be changed, but other than that don't see an issue with this. Is 90% the same thing as isImage.

There is an idea maybe that we can just have a generic mimetype or smth validator, but that is besides this PR.

Comment thread baked_in.go Outdated
@dapzthelegend dapzthelegend force-pushed the feature/audio-validation branch 2 times, most recently from cfd8a26 to fc6e691 Compare March 22, 2026 12:56
@dapzthelegend dapzthelegend force-pushed the feature/audio-validation branch from fc6e691 to a5fba5e Compare April 12, 2026 16:03
@dapzthelegend
Copy link
Copy Markdown
Contributor Author

Hi @zemzale — rebased feature/audio-validation on latest master (7 commits, same upstream changes as #1544). The only conflict was translations/it/it.go (new bcp47_strict_language_tag entry vs. mimetype/audio entries) — resolved by keeping all three tags.

Branch is now conflict-free. Noted that the review decision still shows REVIEW_REQUIRED since @zemzale's earlier review was dismissed after subsequent commits. If the implementation looks good, a fresh approval would unblock merge. Happy to address any remaining concerns.

Copy link
Copy Markdown
Member

@zemzale zemzale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants