-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
132 lines (109 loc) · 2.42 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"encoding/hex"
"flag"
"goVncPVM/goVncRest"
"goVncPVM/goVncTCP"
"goVncPVM/helpers"
"log"
"net"
"time"
"github.com/go-redis/redis"
"github.com/tkanos/gonfig"
)
var redisDB *redis.Client
var tranChannel chan string
type RedisConfiguration struct {
RedisHost string
RedisPort string
RedisDbNum int
}
func connectToRedis() (err error) {
//
redisConf := RedisConfiguration{}
err = gonfig.GetConf("config/redis.json", &redisConf)
if err != nil {
//
log.Fatalln("NO CONFIG FILE. ", err)
}
// var redisDBNumInt int = 1
// redisHost, ok := os.LookupEnv("REDIS_PORT_6379_TCP_ADDR")
// if !ok {
// //
//
// redisHost = "0.0.0.0"
// }
//
// redisPort, ok := os.LookupEnv("REDIS_PORT_6379_TCP_PORT")
// if !ok {
// //
//
// redisPort = "6379"
// }
//
// redisDBNum, ok := os.LookupEnv("REDIS_PORT_6379_DB_NUM")
// if !ok {
// //
//
// redisDBNumInt = 1
//
// } else {
// //
//
// if redisDBNumInt64, err := strconv.ParseInt(redisDBNum, 10, 64); err != nil {
// //
//
// redisDBNumInt = int(redisDBNumInt64)
//
// } else {
// //
//
// redisDBNumInt = 1
// }
// }
redisDB = redis.NewClient(&redis.Options{
Addr: net.JoinHostPort(redisConf.RedisHost, redisConf.RedisPort),
DialTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
PoolSize: 10,
PoolTimeout: 30 * time.Second,
DB: redisConf.RedisDbNum,
})
statusCmd := redisDB.Ping()
if helpers.IsRedisError(statusCmd) {
//
log.Fatalln("No connection to REDIS. ", statusCmd.Err())
return statusCmd.Err()
}
return
}
func main() {
//
privateKeyPtr := flag.String("privateKey",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"A private key associated with your node")
ipPtr := flag.String("ip",
"0.0.0.0",
"Your external IP")
flag.Parse()
privateKey, err := hex.DecodeString(*privateKeyPtr)
if err != nil {
//
panic("WRONG PRIVATE KEY")
}
tranChannel = make(chan string, 1024)
if err := connectToRedis(); err != nil {
//
panic(err.Error())
}
defer redisDB.Close()
go restServer.Start(redisDB, &tranChannel, *ipPtr)
tcpServer.Start(redisDB, &tranChannel, privateKey, *ipPtr)
//
// consoleReader := bufio.NewReader(os.Stdin)
// log.Println("Enter text: ") // Just for better testing. Should be refactored for production
// consoleReader.ReadString('\n')
//
// close(tranChannel)
}