-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
53 lines (38 loc) · 817 Bytes
/
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
package main
import (
"flag"
"log"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"treds/server"
"github.com/panjf2000/gnet/v2"
)
const DefaultPort = "7997"
func main() {
portFlag := flag.String("port", DefaultPort, "Port at which server will listen")
flag.Parse()
var sigs = make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
port := os.Getenv("TREDS_PORT")
if len(port) == 0 {
port = DefaultPort
}
if portFlag != nil && *portFlag != "" {
port = *portFlag
}
portInt, err := strconv.Atoi(port)
if err != nil {
panic(err)
}
tredsServer := server.New(portInt)
log.Fatal(gnet.Run(
tredsServer,
"tcp://0.0.0.0:"+strconv.Itoa(tredsServer.Port),
gnet.WithMulticore(false),
gnet.WithReusePort(false),
gnet.WithTCPKeepAlive(300*time.Second),
))
}