-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
56 lines (44 loc) · 769 Bytes
/
util.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
package main
import (
"fmt"
"net"
"os"
"os/exec"
"os/signal"
"runtime"
"syscall"
)
func clearScreen() {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/c", "cls")
} else {
cmd = exec.Command("clear")
}
cmd.Stdout = os.Stdout
cmd.Run()
}
func waitUntilExit() {
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
done <- true
}()
<-done
}
func maybeIP(value *string) *string {
v := net.ParseIP(*value)
four := v.To4()
six := v.To16()
maybeIP := ""
if four != nil {
maybeIP = four.String()
} else if six != nil {
maybeIP = six.String()
}
return &maybeIP
}