/
main.go
78 lines (71 loc) · 1.49 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
package main
import (
"context"
"flag"
"fmt"
_ "net/http/pprof"
"os"
"github.com/clubpay/ronykit/contrib/tracekit"
"github.com/clubpay/ronykit/kit"
"github.com/clubpay/ronykit/std/clusters/rediscluster"
"github.com/clubpay/ronykit/std/gateways/fasthttp"
"github.com/orlangure/gnomock"
redisContainer "github.com/orlangure/gnomock/preset/redis"
)
func main() {
var (
port int
redis int
)
flag.IntVar(&port, "port", 80, "")
flag.IntVar(&redis, "redis", 0, "")
flag.Parse()
if redis > 0 {
// Create a Redis container.
redisC, err := gnomock.Start(
redisContainer.Preset(
redisContainer.WithVersion("7-alpine"),
),
gnomock.WithUseLocalImagesFirst(),
gnomock.WithOptions(&gnomock.Options{
CustomNamedPorts: map[string]gnomock.Port{
"default": {
Protocol: "tcp",
Port: 6379,
HostPort: 6379,
},
},
}),
)
if err != nil {
panic(err)
}
defer func() {
err := gnomock.Stop(redisC)
if err != nil {
panic(err)
}
}()
}
// Create, start and wait for shutdown signal of the server.
defer kit.NewServer(
kit.WithTrace(
tracekit.B3("ex03"),
),
kit.WithCluster(
rediscluster.MustNew(
"ex03",
rediscluster.WithRedisURL("redis://localhost:6379"),
),
),
kit.WithGateway(
fasthttp.MustNew(
fasthttp.Listen(fmt.Sprintf(":%d", port)),
),
),
kit.WithServiceDesc(serviceDesc.Desc()),
).
Start(context.TODO()).
PrintRoutes(os.Stdout).
Shutdown(context.TODO(), os.Kill, os.Interrupt)
}