-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
90 lines (77 loc) · 1.88 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
/*
* This file is part of wp-server project (https://github.com/AnimeKaizoku/wotoplatform).
* Copyright (c) 2021 ALiwoto.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"crypto/tls"
"log"
"net"
"wp-server/wotoPacks/core/utils/logging"
"wp-server/wotoPacks/core/wotoConfig"
"wp-server/wotoPacks/database"
"wp-server/wotoPacks/entryPoints"
"go.uber.org/zap"
)
func main() {
f := loadLogger()
if f != nil {
defer f()
}
err := runServer()
if err != nil {
log.Fatal(err)
}
}
func runServer() error {
cfg, err := wotoConfig.GetConfig()
if err != nil {
return err
}
var ln net.Listener
if cfg.UseTLS {
cer, err := tls.LoadX509KeyPair("server.pem", "server.key")
if err != nil {
return err
}
config := &tls.Config{
Certificates: []tls.Certificate{cer},
MinVersion: tls.VersionTLS12,
}
ln, err = tls.Listen(cfg.Network, net.JoinHostPort(cfg.Bind, cfg.Port), config)
if err != nil {
return err
}
} else {
ln, err = net.Listen(cfg.Network, net.JoinHostPort(cfg.Bind, cfg.Port))
if err != nil {
return err
}
}
err = database.StartDatabase()
if err != nil {
return err
}
entryPoints.Listen(ln)
return nil
}
func loadLogger() func() {
loggerMgr := logging.InitZapLog(true)
zap.ReplaceGlobals(loggerMgr)
logging.SUGARED = loggerMgr.Sugar()
return func() {
_ = loggerMgr.Sync()
}
}