Configuration options
[]string
List of domains (hosts) that are NOT allowed. URLs with these domains will fail validation. Cannot be set if
onlyDomains is specified.[]string
List of domains (hosts) that are exclusively allowed. URLs must use one of these domains. Cannot be set if
exceptDomains is specified.bool
default:"false"
When true, requires the field value to be a non-empty, valid URL.
Validation rules
The url field validates:- Format: Value must be a valid URL format (including scheme)
- Domain allowlist: If
onlyDomainsis set, URL host must be in the list - Domain blocklist: If
exceptDomainsis set, URL host must NOT be in the list - Required: If enabled, value cannot be empty
Go examples
- Basic usage
- Restrict to specific domains
- Block specific domains
- Multiple URL fields
Database column type
Common use cases
Domain matching
The domain matching is exact and includes the port if specified. For example:
"example.com"matcheshttps://example.com/pathbut NOThttps://www.example.com/path"example.com:8080"matcheshttps://example.com:8080but NOThttps://example.com
Best practices
- URLs must include the scheme (http://, https://, etc.)
- Use
onlyDomainswhen restricting to specific platforms or services - Use
exceptDomainsto block known malicious or unwanted domains - Domain matching includes the port number if present in the URL
- Consider validating URL accessibility separately if needed
Zero value
The zero value for url fields is an empty string"".