-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.go
73 lines (59 loc) · 1.75 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
package main
import (
"fmt"
"os"
"go.uber.org/yarpc"
"go.uber.org/yarpc/transport/http"
"go.uber.org/yarpc/transport/tchannel"
"go.uber.org/zap"
"github.com/coinbase/cadence-ruby/proxy/internal"
"github.com/coinbase/cadence-ruby/proxy/gen/cadence/workflowserviceserver"
)
func main() {
bindAddress := "127.0.0.1:6666"
cadenceAddress := "127.0.0.1:7933"
if in := os.Getenv("BIND_ADDRESS"); in != "" {
bindAddress = in
}
if out := os.Getenv("CADENCE_ADDRESS"); out != "" {
cadenceAddress = out
}
logger, _ := zap.NewProduction()
defer logger.Sync()
dispatcher := initDispatcher(logger, bindAddress, cadenceAddress)
handler := internal.NewProxyHandler(dispatcher.ClientConfig("cadence-frontend"))
dispatcher.Register(workflowserviceserver.New(handler))
if err := dispatcher.Start(); err != nil {
fmt.Println("failed to start Dispatcher: %v", err)
return
}
defer dispatcher.Stop()
select {}
}
func initDispatcher(logger *zap.Logger, bindAddress string, cadenceAddress string) *yarpc.Dispatcher {
httpTransport := http.NewTransport()
tchannelTransport, err := tchannel.NewChannelTransport(tchannel.ServiceName("cadence-proxy-client"))
if err != nil {
fmt.Println("failed to generate transport: %v", err)
}
config := yarpc.Config{
Name: "cadence-proxy",
Inbounds: yarpc.Inbounds{
httpTransport.NewInbound(bindAddress),
},
Outbounds: yarpc.Outbounds{
"cadence-frontend": {
Unary: tchannelTransport.NewSingleOutbound(cadenceAddress),
},
},
Logging: yarpc.LoggingConfig{
Zap: logger,
},
}
if timing := os.Getenv("TIMING"); timing == "1" {
config.OutboundMiddleware = yarpc.OutboundMiddleware{
Unary: yarpc.UnaryOutboundMiddleware(internal.TimingLogMiddleware{}),
}
}
return yarpc.NewDispatcher(config)
}