forked from topfreegames/pitaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (37 loc) · 1004 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
package main
import (
"flag"
"fmt"
"strings"
"github.com/felippeduran/pitaya/v2"
"github.com/felippeduran/pitaya/v2/acceptor"
"github.com/felippeduran/pitaya/v2/component"
"github.com/felippeduran/pitaya/v2/config"
"github.com/felippeduran/pitaya/v2/examples/demo/custom_metrics/services"
"github.com/spf13/viper"
)
var app pitaya.Pitaya
func main() {
port := flag.Int("port", 3250, "the port to listen")
svType := "room"
isFrontend := true
flag.Parse()
cfg := viper.New()
cfg.AddConfigPath(".")
cfg.SetConfigName("config")
err := cfg.ReadInConfig()
if err != nil {
panic(err)
}
tcp := acceptor.NewTCPAcceptor(fmt.Sprintf(":%d", *port))
conf := config.NewConfig(cfg)
builder := pitaya.NewBuilderWithConfigs(isFrontend, svType, pitaya.Cluster, map[string]string{}, conf)
builder.AddAcceptor(tcp)
app = builder.Build()
defer app.Shutdown()
app.Register(services.NewRoom(app),
component.WithName("room"),
component.WithNameFunc(strings.ToLower),
)
app.Start()
}