-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
79 lines (74 loc) · 2.27 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := cli.NewApp()
app.Usage = "whois-json"
app.EnableBashCompletion = true
app.Commands = []*cli.Command{
{
Name: "json",
Usage: "json that containe the domain result for who is",
Flags: []cli.Flag{
&cli.StringFlag{Name: "domain", Required: true, Aliases: []string{"d"}, Usage: "domain want to check"},
},
Action: func(c *cli.Context) error {
domain, e := NewDomain(c.String("domain"))
if e != nil {
return cli.Exit(e, 128)
}
result, e := DomainWhois(domain)
if e != nil {
return cli.Exit(e, 1)
}
json, _ := json.Marshal(result)
fmt.Println(string(json))
return nil
},
},
{
Name: "validate",
Usage: "validate domain and return domain data",
Flags: []cli.Flag{
&cli.StringFlag{Name: "domain", Required: true, Aliases: []string{"d"}, Usage: "domain want to check"},
},
Action: func(c *cli.Context) error {
domainType, e := NewDomain(c.String("domain"))
if e != nil {
return cli.Exit(e, 128)
}
json, _ := json.Marshal(domainType)
fmt.Println(string(json))
return nil
},
},
{
Name: "webserver",
Usage: "HTTP Server for REST API",
Flags: []cli.Flag{
&cli.StringFlag{Name: "listen", Aliases: []string{"l"}, EnvVars: []string{"ASM_WS_LISTEN"}, Value: "0.0.0.0:9000", DefaultText: "0.0.0.0:9000", Usage: "HTTP address/port want to listen"},
&cli.StringFlag{Name: "base-url", Aliases: []string{"b"}, EnvVars: []string{"ASM_WS_BASEURL"}, Value: "/", DefaultText: "/", Usage: "Base URL to serve HTTP endpoints"},
&cli.StringFlag{Name: "username", Aliases: []string{"user"}, EnvVars: []string{"ASM_WS_BASIC_USERNAME"}, Value: "username", DefaultText: "username", Usage: "Basic auth username"},
&cli.StringFlag{Name: "password", Aliases: []string{"pass"}, EnvVars: []string{"ASM_WS_BASIC_PASSWORD"}, Value: "password", DefaultText: "password", Usage: "Basic auth password"},
},
Action: func(c *cli.Context) error {
app, _ := HTTPServer(
c.String("base-url"),
c.String("username"),
c.String("password"),
)
app.Listen(c.String("listen"))
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}