-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (32 loc) · 759 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
package main
import (
"flag"
"github.com/pterm/pterm"
"net"
"time"
)
func main() {
ipAddress := GetLocalIP()
ip := flag.String("ip", ipAddress, "Server IP address")
port := flag.Int("port", 9001, "Server Port Address")
flag.Parse()
ScreenLogo()
serverInfo, _ := pterm.DefaultSpinner.Start("Server Starting ...")
time.Sleep(time.Second * 2)
CreateAndStartServer(*ip, *port, serverInfo)
}
func GetLocalIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
for _, address := range addrs {
// check the address type and if it is not a loopback the display it
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return ""
}