-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (62 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
package main
//add it in line 57 in case of some pizdetz runtime.Gosched()
import (
"concurrent-tcp-server/config"
"concurrent-tcp-server/models/constant"
"concurrent-tcp-server/parser"
"concurrent-tcp-server/responses/repository"
"concurrent-tcp-server/server"
"github.com/joho/godotenv"
"log"
"net"
"net/http"
"runtime"
"sync"
)
// function to load env-project variables
func init() {
// loads values from .env into the system
if err := godotenv.Load(); err != nil {
log.Print("No .env file found")
}
}
func main() {
initializedConfigs := config.New()
var myDataInArray = make(map[string]string)
filledGroupedData := parser.GroupedData{}
mutex := &sync.Mutex{}
wg := &sync.WaitGroup{}
connection := new(net.Conn)
runtime.GOMAXPROCS(7) // allow the run-time support to utilize more than one OS thread(in this case 7)
var client = new(http.Client)
responseRepository := repository.NewResponseRepository(client, mutex, wg)
homeAndToken, err := responseRepository.GetTokenAndHomeLink("http://" + initializedConfigs.Host + initializedConfigs.RemoteServerPort + constant.TokenUri)
if err != nil {
log.Println("home and token error:", err)
}
myRoutes, err := responseRepository.GetAllRoutes("http://"+initializedConfigs.Host+initializedConfigs.RemoteServerPort+homeAndToken.HomeLink, homeAndToken.AccessToken)
if err != nil {
log.Println(err)
}
var mainMap = myRoutes.Link
for _, v := range mainMap {
wg.Add(1) // spawn goroutines
go func(value string) {
defer wg.Done()
responseRepository.GetLinkResponse("http://"+initializedConfigs.Host+initializedConfigs.RemoteServerPort+value, homeAndToken.AccessToken, myDataInArray)
if err != nil {
log.Println(err)
}
}(v)
}
wg.Wait()
for k, v := range myDataInArray {
if dataToParse, exists := parser.ParsePlatforms[v]; exists {
if err := dataToParse.Parse(k, &filledGroupedData); err != nil {
log.Println(err)
}
}
}
myServer := server.NewServer(*connection, filledGroupedData.FullMap)
myServer.RunServer(initializedConfigs.TcpServerPort)
}