/
main.go
48 lines (45 loc) · 924 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "Website Health Checker",
Usage: "A small tool to check if a website is running and reachable or not.",
Version: "1.0",
Authors: []*cli.Author{
{Name:"Carlos E. Torres", Email: "cetorres@cetorres.com"},
},
Copyright: "2023 Carlos E. Torres",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "domain",
Aliases: []string{"d"},
Usage: "domain name to check",
Required: true,
},
&cli.StringFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "port number to check",
Required: false,
},
},
Action: func(c *cli.Context) error{
port := c.String("port")
if c.String("port") == "" {
port = "80"
}
status := Check(c.String("domain"), port)
fmt.Println(status)
return nil
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}