This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.pb.cgen.go
99 lines (77 loc) · 2.65 KB
/
example.pb.cgen.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
91
92
93
94
95
96
97
98
99
// Code generated by aws-grpc-service-proxy. DO NOT EDIT.
package proto
import (
"context"
"crypto/tls"
"math"
"net"
"time"
"github.com/andersnormal/pkg/server"
o "github.com/cgentron/protoc-gen-cgentron/pkg/opts"
"github.com/cgentron/protoc-gen-cgentron/pkg/proxy"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
grpc_health_v1 "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/keepalive"
)
type srv struct {
opts *o.Opts
}
type service struct {
tlsCfg *tls.Config
logger *zap.Logger
UnimplementedExampleServer
}
func New(opts *o.Opts) proxy.Listener {
s := new(srv)
s.opts = opts
return s
}
func NewProxy(opts *o.Opts) proxy.Proxy {
s := New(opts)
p := proxy.New(s, opts)
return p
}
func (s *srv) Start(ctx context.Context, ready server.ReadyFunc) func() error {
return func() error {
lis, err := net.Listen("tcp", s.opts.Addr)
if err != nil {
return err
}
ll := s.opts.Logger.With(zap.String("addr", s.opts.Addr))
srv := &service{
logger: s.opts.Logger,
}
tlsConfig := &tls.Config{}
tlsConfig.InsecureSkipVerify = true
srv.tlsCfg = tlsConfig
var kaep = keepalive.EnforcementPolicy{
MinTime: 5 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection
PermitWithoutStream: true, // Allow pings even when there are no active streams
}
var kasp = keepalive.ServerParameters{
MaxConnectionIdle: time.Duration(math.MaxInt64), // If a client is idle for 15 seconds, send a GOAWAY
MaxConnectionAge: time.Duration(math.MaxInt64), // If any connection is alive for more than 30 seconds, send a GOAWAY
MaxConnectionAgeGrace: 5 * time.Second, // Allow 5 seconds for pending RPCs to complete before forcibly closing connections
Time: 5 * time.Second, // Ping the client if it is idle for 5 seconds to ensure the connection is still active
Timeout: 1 * time.Second, // Wait 1 second for the ping ack before assuming the connection is dead
}
grpc_zap.ReplaceGrpcLogger(ll)
ss := grpc.NewServer(
grpc.KeepaliveEnforcementPolicy(kaep),
grpc.KeepaliveParams(kasp),
grpc_middleware.WithUnaryServerChain(grpc_zap.UnaryServerInterceptor(ll)))
RegisterExampleServer(ss, srv)
grpc_health_v1.RegisterHealthServer(ss, health.NewServer())
// grpc_health_v1.RegisterHealthServer(ss, srv)
ready()
ll.Info("start listening")
if err := ss.Serve(lis); err != nil {
return err
}
return nil
}
}