/
rpc.go
49 lines (41 loc) · 1.32 KB
/
rpc.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
package main
import (
"log"
"os"
"git-wip-us.apache.org/repos/asf/thrift.git/lib/go/thrift"
"github.com/oleksandr/idp/config"
"github.com/oleksandr/idp/rpc"
"github.com/oleksandr/idp/rpc/generated/services"
"github.com/oleksandr/idp/usecases"
)
func startRPCServer(exitCh chan bool,
domainInteractor usecases.DomainInteractor,
userInteractor usecases.UserInteractor,
sessionInteractor usecases.SessionInteractor,
rbacInteractor usecases.RBACInteractor) {
addr := os.Getenv(config.EnvIDPRPCAddr)
if addr == "" {
addr = ":8001"
}
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := thrift.NewTBufferedTransportFactory(8192)
transport, err := thrift.NewTServerSocket(addr)
if err != nil {
log.Println("Error creating server transport: %s", err)
exitCh <- true
return
}
handler := rpc.NewIdentityProviderHandler()
handler.DomainInteractor = domainInteractor
handler.UserInteractor = userInteractor
handler.SessionInteractor = sessionInteractor
handler.RBACInteractor = rbacInteractor
processor := services.NewIdentityProviderProcessor(handler)
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
log.Println("RPC API Server listening", addr)
err = server.Serve()
if err != nil {
log.Println("Error in Serve:", err)
exitCh <- true
}
}