-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (38 loc) · 1.26 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
package main
import (
"github.com/togettoyou/go-kit-example/hello/dao"
"github.com/togettoyou/go-kit-example/hello/endpoints"
"github.com/togettoyou/go-kit-example/hello/service"
grpcTransport "github.com/togettoyou/go-kit-example/hello/transport/grpc"
"github.com/togettoyou/go-kit-example/hello/transport/grpc/pb"
httpTransport "github.com/togettoyou/go-kit-example/hello/transport/http"
"google.golang.org/grpc"
"log"
"net"
"net/http"
)
func main() {
helloDao := dao.NewHelloDAOImpl()
helloService := service.NewHelloServiceImpl(helloDao)
helloEndpoint := endpoints.HelloEndPoints{
GetNameEndpoint: endpoints.MakeGetNameEndpoint(helloService),
GetAgeEndpoint: endpoints.MakeGetAgeEndpoint(helloService),
}
go newHttpServer(helloEndpoint)
go newGRPCServer(helloEndpoint)
select {}
}
func newHttpServer(endpoints endpoints.HelloEndPoints) {
httpHandler := httpTransport.NewHttpHandler(endpoints)
log.Fatalln(http.ListenAndServe(":8888", httpHandler))
}
func newGRPCServer(endpoints endpoints.HelloEndPoints) {
server := grpc.NewServer()
grpcHandler := grpcTransport.NewGRPCHandler(endpoints)
pb.RegisterHelloServiceServer(server, grpcHandler)
lis, err := net.Listen("tcp", ":9999")
if err != nil {
log.Fatalln(err)
}
log.Fatalln(server.Serve(lis))
}