Skip to content

Commit

Permalink
feat: checking the min length of the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza12700 committed Sep 23, 2024
1 parent e3b50ee commit 51aaf3d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions validate/validate_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type DomainTooLong struct{}

type InvalidDomainFormat struct{}

type UrlTooShort struct{}

type UrlTooLong struct {
url uint
}
Expand All @@ -30,6 +32,10 @@ func (link *UrlTooLong) Error() string {
return fmt.Sprintf("URL is too long, max lenght is 1000 characters, but got %v", link.url)
}

func (link *UrlTooShort) Error() string {
return "URL is too short, min lenght is 4 characters"
}

func (_ *InvalidDomainName) Error() string {
return "URL doesn't contain a validate TLD (Top-Level Domain)"
}
Expand All @@ -45,6 +51,8 @@ func (_ *DomainTooLong) Error() string {
func ValidateUrl(link string) error {
if len(link) > 1000 {
return &UrlTooLong{url: uint(len(link))}
} else if len(link) < 4 {
return &UrlTooShort{}
}

if !strings.Contains(link, ".") {
Expand Down

0 comments on commit 51aaf3d

Please sign in to comment.