This commit is contained in:
Kar
2026-03-10 20:18:25 +05:30
commit 4e1a541816
6 changed files with 89 additions and 0 deletions

40
README.md Normal file
View File

@@ -0,0 +1,40 @@
# is-valid-domain
A CLI tool to validate domain names using the public suffix list from `golang.org/x/net/publicsuffix`.
## Usage
```bash
./is-valid-domain <domain>
```
## Examples
```bash
./is-valid-domain 029.cyou # Output: valid
./is-valid-domain siliconpin.co.in # Output: valid
./is-valid-domain co.siliconpin.in # Output: subdomain
./is-valid-domain invalid..domain # Output: invalid
```
## Output Categories
- **valid** - The domain is a registrable domain (effective TLD+1)
- **subdomain** - The domain is a subdomain of a registrable domain
- **invalid** - The domain is malformed or not a valid domain name
## Installation
```bash
go build -o is-valid-domain main.go
```
## How it Works
The tool uses `publicsuffix.EffectiveTLDPlusOne()` to determine the registrable domain:
1. If the input domain exactly matches the effective TLD+1 → **valid**
2. If the input domain is longer than the effective TLD+1 → **subdomain**
3. If there's an error parsing the domain → **invalid**
This leverages the official public suffix list to correctly handle complex TLD structures like `.co.in`, `.co.uk`, etc.