-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmux_server.go
42 lines (35 loc) · 986 Bytes
/
cmux_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
package sfx
import (
"go.uber.org/fx"
"go.uber.org/zap"
"github.com/gstones/moke-kit/server/internal/cmux"
"github.com/gstones/moke-kit/server/siface"
)
// ConnectionMux module:listen and serve same port for different protocols
// github.com/soheilhy/cmux
type ConnectionMuxParams struct {
fx.In
ConnectionMux siface.IConnectionMux `name:"ConnectionMux"`
}
type ConnectionMuxResult struct {
fx.Out
ConnectionMux siface.IConnectionMux `name:"ConnectionMux"`
}
func (cmr *ConnectionMuxResult) Execute(
l *zap.Logger,
g SettingsParams,
s SecuritySettingsParams,
) (err error) {
if s.TLSEnable {
cmr.ConnectionMux, err = cmux.NewTlsConnectionMux(l, g.Port, s.ServerCert, s.ServerKey, s.ClientCaCert)
} else {
cmr.ConnectionMux, err = cmux.NewConnectionMux(l, g.Port)
}
return
}
var ConnectionMuxModule = fx.Provide(
func(l *zap.Logger, g SettingsParams, s SecuritySettingsParams) (out ConnectionMuxResult, err error) {
err = out.Execute(l, g, s)
return
},
)