-
Notifications
You must be signed in to change notification settings - Fork 0
/
up.go
82 lines (65 loc) · 1.44 KB
/
up.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
80
81
82
package main
import (
"fmt"
"net/http"
"os"
"time"
)
func main() {
client := http.Client{
Timeout: 5 * time.Second,
}
resp, err := client.Get("http://google.com")
var first string
_ = resp
if os.Args != nil && len(os.Args) > 1 {
first = os.Args[1]
} else {
first = "unknown"
}
if first == "unknown" {
getLongAnswer(err)
} else if first == "long" {
getLongAnswer(err)
} else if first == "short" {
getShortAnswer(err)
} else if first == "help" {
helpScreen()
} else if first == "--help" {
helpScreen()
} else {
fmt.Println("Option not defined")
}
}
func helpScreen() {
fmt.Println("Up (http-up) version 1.1.0")
fmt.Println("By Elijah Cruz")
fmt.Println()
fmt.Println("Allows you to check the status of your internet")
fmt.Println()
fmt.Printf("")
fmt.Println("Options:")
fmt.Println(" - <none>: Equivalent of long")
fmt.Println(" - long: Displays a longer more human readable version of your internet status.")
fmt.Println(" - short: Displays either \"up\" or \"down\" depending on your internet is up or down.")
fmt.Println(" - help: This help message")
}
func getLongAnswer(err interface{}) {
fmt.Println("Getting you internet status")
if err != nil {
fmt.Println("Internet is down")
os.Exit(1)
} else {
fmt.Println("Internet is working")
os.Exit(0)
}
}
func getShortAnswer(err interface{}) {
if err != nil {
fmt.Println("down")
os.Exit(1)
} else {
fmt.Println("up")
os.Exit(0)
}
}