/
main.go
75 lines (66 loc) 路 1.48 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
package main
import (
"context"
"github.com/h2non/bimg"
"github.com/leaq-ru/image/config"
"github.com/leaq-ru/image/imageimpl"
"github.com/leaq-ru/image/logger"
"github.com/leaq-ru/image/stan"
graceful "github.com/leaq-ru/lib-graceful"
"github.com/leaq-ru/proto/codegen/go/image"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"net"
"strings"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
bimg.VipsCacheSetMaxMem(0)
bimg.VipsCacheSetMax(0)
srv := grpc.NewServer()
img := imageimpl.NewServer()
lis, err := net.Listen("tcp", strings.Join([]string{
"0.0.0.0",
config.Env.Grpc.Port,
}, ":"))
logger.Must(err)
grpc_health_v1.RegisterHealthServer(srv, health.NewServer())
image.RegisterImageServer(srv, img)
companyNew, err := stan.NewConsumer(
logger.Log,
stan.Conn,
config.Env.STAN.SubjectCompanyNew,
config.ServiceName,
3,
img.ConsumeCompanyNew,
)
logger.Must(err)
deleteImage, err := stan.NewConsumer(
logger.Log,
stan.Conn,
config.Env.STAN.SubjectDeleteImage,
config.ServiceName,
3,
img.ConsumeDeleteImage,
)
logger.Must(err)
var eg errgroup.Group
eg.Go(func() error {
graceful.HandleSignals(srv.GracefulStop, cancel)
return nil
})
eg.Go(func() error {
return srv.Serve(lis)
})
eg.Go(func() error {
companyNew.Serve(ctx)
return nil
})
eg.Go(func() error {
deleteImage.Serve(ctx)
return nil
})
logger.Must(eg.Wait())
}