-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
69 lines (54 loc) · 1.08 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
package main
import (
"net/http"
"os"
"strconv"
uuid "github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
"vitess.io/vitess/go/pools"
)
// ConfigT as db conf, etc
type ConfigT struct {
Port int `yaml:"port"`
Redis string `yaml:"redis"`
}
// EnvT as db, etc
type EnvT struct {
RedisPool *pools.ResourcePool
WsHub *WebSocketsHub
JwtKey string
ServerID string
}
// Conf var as storage
var Conf ConfigT
// Env var as storage
var Env EnvT
func startHTTP() {
http.Handle("/", &WebSocketRespT{})
addr := ":" + strconv.Itoa(Conf.Port)
log.Warnln("about to start server addr:", addr)
err := http.ListenAndServe(addr, nil)
if err != nil {
log.Fatal(err)
}
}
func main() {
buf, err := os.ReadFile("config.yml")
if err != nil {
log.Fatalln("Cannot read config.yml err:", err)
return
}
err = yaml.Unmarshal(buf, &Conf)
if err != nil {
log.Fatalln("config err:", err)
return
}
Env.ServerID = uuid.New()
InitRedisPool()
Env.WsHub = newHub()
go Env.WsHub.run()
initQueueClient(Env.WsHub)
go startHTTP()
startQueueProcessing()
}