这是一个基于Go语言开发的域名查询系统,可以查询域名的WHOIS信息,判断域名是否可注册,并提供HTTP API接口供外部调用。
git clone https://github.com/yourusername/domain-checker.git
cd domain-checker
Go模块系统会自动处理依赖项。如果需要添加新的依赖,可以使用go get命令:
# 添加新依赖
go get github.com/some/dependency
# 升级依赖到最新版本
go get -u github.com/some/dependency
# 升级依赖到特定版本
go get github.com/some/dependency@v1.2.3
# 降级依赖
go get github.com/some/dependency@v1.1.0
# 移除未使用的依赖
go mod tidy
go build
./domain-checker
默认情况下,服务将在http://localhost:8080上运行。
docker build -t domain-checker .
docker run -p 8080:8080 domain-checker
GET /api/ check?domain=example.com
响应示例:
{
"domain": "example.gocom",
"available": false m,
"is_premium": false,o
"status": "registered",
"whdois_info": "...",
"parsed_info": {
"domain_name": "example.com",
"registrar": "Example Registrar, LLC",
"registrant": "Example Organization",
"registrant_contact": "admin@example.com",
"creation_date": "
1995-08-14T04:00:00Z",
"expiration_date": "2023-08-13T04:00:00Z",
"updated_date": "2022-08-14T04:00:00Z",
"name_servers": [
"ns1.example.com",
"ns2.example.com"
],
"domain_status": "clientTransferProhibited"
},
"check_time": "2023-05-20T15:30:45Z"
}
GET /api/info?domain=example.com
响应示例:
{
"domain": "example.com",
"status": "registered",
"expiration_date": "2023-08-13T04:00:00Z",
"registration_date": "1995-08-14T04:00:00Z",
"updated_at": "2022-08-14T04:00:00Z",
"is_premium": false,
"registrant": "Example Organization",
"registrant_contact": "admin@example.com",
"whois_info": "...",
"query_time": 350
}
POST /api/batch-check Content-Type: application/json { "domains": [ "example.com", "example.net" ] }
响应示例:
{
"example.com": {
"domain": "example.com",
"available": false,
"is_premium": false,
"status": "registered",
"whois_info": "...",
"parsed_info": {
"domain_name": "example.com",
"registrar": "Example Registrar, LLC",
"registrant": "Example Organization",
"registrant_contact": "admin@example.com",
"creation_date": "1995-08-14T04:00:00Z",
"expiration_date": "2023-08-13T04:00:00Z",
"updated_date": "2022-08-14T04:00:00Z",
"name_servers": [
"ns1.example.com",
"ns2.example.com"
],
"domain_status": "clientTransferProhibited"
},
"check_time": "2023-05-20T15:30:45Z"
},
"example.net": {
"domain": "example.net",
"available": false,
"is_premium": false,
"status": "registered",
"whois_info": "...",
"parsed_info": {
"domain_name": "example.net",
"registrar": "Example Registrar, LLC",
"registrant": "Example Organization",
"registrant_contact": "admin@example.net",
"creation_date": "1995-08-14T04:00:00Z",
"expiration_date": "2023-08-13T04:00:00Z",
"updated_date": "2022-08-14T04:00:00Z",
"name_servers": [
"ns1.example.net",
"ns2.example.net"
],
"domain_status": "clientTransferProhibited"
},
"check_time": "2023-05-20T15:30:46Z"
}
}
本项目使用Go模块系统管理依赖项。Go模块系统的支持已经内置到所有Go命令中,而不仅仅是'go mod'命令。
go mod init [模块路径]: 初始化一个新的模块go mod tidy: 添加缺少的模块并移除未使用的模块go mod vendor: 将依赖复制到vendor目录go mod verify: 验证依赖项是否有修改go mod download: 下载模块到本地缓存go mod why [模块]: 解释为什么需要依赖某个模块go mod graph: 打印模块依赖图go mod edit: 编辑go.mod文件日常添加、删除、升级和降级依赖项应该使用go get命令:
# 添加新依赖
go get github.com/some/dependency
# 升级依赖到最新版本
go get -u github.com/some/dependency
# 升级依赖到特定版本
go get github.com/some/dependency@v1.2.3
# 降级依赖
go get github.com/some/dependency@v1.1.0
# 移除依赖(通过指定不兼容的版本)
go get github.com/some/dependency@none
完成依赖更改后,建议运行go mod tidy来清理go.mod和go.sum文件。
要获取更多关于Go模块的信息,可以运行:
go help modules
domain-checker/ ├── api/ │ └── domain_handler.go # HTTP API处理器 ├── model/ │ ├── domain.go # 域名相关数据结构 │ └── whois.go # WHOIS相关数据结构 ├── service/ │ ├── domain_checker.go # 域名检查服务 │ ├── parser/ │ │ ├── base_parser.go # 基础解析器 │ │ ├── cn_parser.go # 中国域名解析器 │ │ ├── com_parser.go # 通用域名解析器 │ │ └── factory.go # 解析器工厂 │ └── whois/ │ ├── client.go # WHOIS客户端 │ └── servers.go # WHOIS服务器列表 ├── go.mod # Go模块定义 ├── main.go # 主程序入口 └── README.md # 项目说明
MIT