Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement Request - Add IsActiveURL Validation Rule #257

Open
sCuz12 opened this issue Jan 30, 2024 · 1 comment
Open

Enhancement Request - Add IsActiveURL Validation Rule #257

sCuz12 opened this issue Jan 30, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@sCuz12
Copy link

sCuz12 commented Jan 30, 2024

Issue Summary:

I would like to request the addition of a new validation rule called "IsActiveURL" to the validation package. This rule will be used to validate whether a given URL is an active and accessible website.

Description:
Currently, the validation package provides various rules for common validation tasks. However, there is a need for a specific rule to check if a URL is not only valid in format but also leads to an active website. This is especially useful for scenarios where we want to ensure that URLs provided by users actually lead to live webpages.

Expected Behavior:
The IsActiveURL validation rule should make an HTTP request to the provided URL and confirm that the URL is reachable and returns a valid response (e.g., status code 200). If the URL is unreachable or returns an invalid response, the validation should fail

Use Case:
Imagine a scenario where we have a form field for users to input their website URLs. We want to ensure that the URLs they provide are not only correctly formatted but also lead to active websites. This can be crucial for applications that rely on accurate and functioning URLs.

Example
type User struct { Website string `validate:"isActiveURL"` }

@inhere inhere added the question Further information is requested label Jan 30, 2024
@inhere
Copy link
Member

inhere commented Jan 30, 2024

@sCuz12 Maybe you should add a custom validator like isActiveURL

global add:

validate.AddValidator("isActiveURL", func(val string) bool {
	// ... check the URL: val
	// eg. http.Get(val)
	return true
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants