-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.go
71 lines (60 loc) · 1.98 KB
/
server.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
package test
import (
"net/http"
lm "github.com/alexfalkowski/go-service/limiter"
"github.com/alexfalkowski/go-service/runtime"
"github.com/alexfalkowski/go-service/security/token"
"github.com/alexfalkowski/go-service/telemetry/tracer"
v1 "github.com/alexfalkowski/go-service/test/greet/v1"
"github.com/alexfalkowski/go-service/transport"
tg "github.com/alexfalkowski/go-service/transport/grpc"
th "github.com/alexfalkowski/go-service/transport/http"
"github.com/sethvargo/go-limiter"
"github.com/urfave/negroni/v3"
"go.opentelemetry.io/otel/metric"
"go.uber.org/fx"
"go.uber.org/zap"
)
// Server for test.
type Server struct {
Lifecycle fx.Lifecycle
Meter metric.Meter
Verifier token.Verifier
Mux *http.ServeMux
HTTP *th.Server
GRPC *tg.Server
Transport *transport.Config
Tracer *tracer.Config
Limiter limiter.Store
Key lm.KeyFunc
Logger *zap.Logger
VerifyAuth bool
}
// Register server.
func (s *Server) Register() {
sh := NewShutdowner()
tracer, err := tracer.NewTracer(s.Lifecycle, Environment, Version, Name, s.Tracer, s.Logger)
runtime.Must(err)
h, err := th.NewServer(th.ServerParams{
Shutdowner: sh, Mux: s.Mux,
Config: s.Transport.HTTP, Logger: s.Logger,
Tracer: tracer, Meter: s.Meter,
Limiter: s.Limiter, Key: s.Key, Handlers: []negroni.Handler{&none{}},
Verifier: s.Verifier, UserAgent: UserAgent, Version: Version,
})
runtime.Must(err)
s.HTTP = h
g, err := tg.NewServer(tg.ServerParams{
Shutdowner: sh, Config: s.Transport.GRPC, Logger: s.Logger,
Tracer: tracer, Meter: s.Meter, Limiter: s.Limiter, Key: s.Key,
Verifier: s.Verifier, UserAgent: UserAgent, Version: Version,
})
runtime.Must(err)
s.GRPC = g
v1.RegisterGreeterServiceServer(g.Server(), NewService(s.VerifyAuth))
transport.Register(transport.RegisterParams{Lifecycle: s.Lifecycle, Servers: []transport.Server{h, g}})
}
type none struct{}
func (*none) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
next(rw, r)
}