-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
82 lines (74 loc) · 2.02 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
80
81
82
package main
import (
"fmt"
"log"
"net"
"online"
"os"
"os/exec"
"runtime"
"servehttp"
"server"
"strings"
"time"
"update"
)
func main() {
//do u need something before to start server,,, get it here
startTime := time.Now()
updeTime, reqHeader, err := update.UpdateNUtv()
if err != nil {
fmt.Errorf("Error found in updating your NUtv app%v", err)
}
fmt.Println(updeTime)
if b := startTime.Before(updeTime); b == false {
os.Exit(33)
}
err = online.OnlineList()
if err != nil {
fmt.Println(err)
}
//procedd to make server which let it run forever(app on lifespan)
//in server only we will call client server which is will instatiate it which will also run for same life span
//and then server and client will comminaticate with channels
addr := strings.Split(reqHeader.MyAddr.String(), "/")
tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:6969", addr[0]))
l, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
fmt.Errorf("not able to listen%v", err)
}
go servehttp.ServeHttp()
openbrowser("http://127.0.0.1:8080")
fmt.Println("browser is just opened")
for {
con, err := l.Accept()
if err != nil {
fmt.Errorf("not able to accept listner %v", err)
continue
}
fmt.Println("accpted a new connection and about to serve him")
go server.Server(con, reqHeader)
}
}
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
log.Fatal(err)
}
}
//before making connection with your own nutv client http server
//you must first check you carry updated online list
//then ask from every online node server for their req header
//you append your list to all collected list
//and start your http server with list arguments so that list can be viewed in browser
//and after you will be ready to serve your list