From ca099eb6f166aae3c545b6c2ca8bd80e2dd70a33 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Sat, 16 Mar 2019 00:23:31 -0700 Subject: [PATCH] Addd demo main --- cmd/demo/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/demo/main.go b/cmd/demo/main.go index d2cdd06e2..c4adade86 100644 --- a/cmd/demo/main.go +++ b/cmd/demo/main.go @@ -77,6 +77,29 @@ func Result(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(res) } +// Result processes /result end point. +func PickWinner(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + json.NewEncoder(w).Encode("") + msg := &msg_pb.Message{ + Type: msg_pb.MessageType_LOTTERY_REQUEST, + Request: &msg_pb.Message_LotteryRequest{ + LotteryRequest: &msg_pb.LotteryRequest{ + Type: msg_pb.LotteryRequest_PICK_WINNER, + }, + }, + } + + res, err := grpcClient.Process(msg) + if err != nil { + fmt.Println(err) + json.NewEncoder(w).Encode("") + return + } + json.NewEncoder(w).Encode(res) +} + func main() { addr := net.JoinHostPort("", Port) @@ -86,6 +109,7 @@ func main() { router.Path("/enter").HandlerFunc(Enter) router.Path("/result").HandlerFunc(Result) + router.Path("/winner").HandlerFunc(PickWinner) server := &http.Server{Addr: addr, Handler: router} fmt.Println("Serving")