-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdapHandler.go
44 lines (36 loc) · 981 Bytes
/
rdapHandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"net/http"
"strings"
"github.com/labstack/echo/v4"
)
func rdapHandler(c echo.Context) error {
domain := c.Param("domain")
if domain == "" {
return c.String(http.StatusNotAcceptable, "No domain specified")
}
lastDot := strings.LastIndex(domain, ".")
if lastDot == -1 {
return c.String(http.StatusNotAcceptable, "No . in domain")
}
if lastDot == len(domain)-1 {
return c.String(http.StatusNotAcceptable, "Domain cannot end with .")
}
tld := domain[lastDot+1:]
redirect := redirectMap[tld]
if redirect != "" {
return c.Redirect(redirectStatus, fmt.Sprintf("%sdomain/%s", redirect, domain))
}
whois := whoisMap[tld]
if whois == "" {
return c.String(http.StatusOK, fmt.Sprintf("Unable to handle %s (%s)\n", domain, tld))
}
status, result := whoisLookup(whois, domain, c.QueryParam("format"))
switch result.(type) {
case string:
return c.String(status, result.(string))
default:
return c.JSON(status, result)
}
}