checkoutservice: add code stubs, TODO implement
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
af9db7b021
commit
164e52fa44
4 changed files with 2471 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
bin/
|
||||||
|
pkg/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.pyc
|
*.pyc
|
||||||
*.swp
|
*.swp
|
||||||
|
|
6
src/checkoutservice/genproto.sh
Executable file
6
src/checkoutservice/genproto.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
PATH=$PATH:$GOPATH/bin
|
||||||
|
protodir=../../pb
|
||||||
|
|
||||||
|
protoc --go_out=plugins=grpc:genproto -I $protodir $protodir/demo.proto
|
2393
src/checkoutservice/genproto/demo.pb.go
Normal file
2393
src/checkoutservice/genproto/demo.pb.go
Normal file
File diff suppressed because it is too large
Load diff
70
src/checkoutservice/main.go
Normal file
70
src/checkoutservice/main.go
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
pb "./genproto"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
listenPort = "5000"
|
||||||
|
)
|
||||||
|
|
||||||
|
type checkoutService struct {
|
||||||
|
productCatalogSvcAddr string
|
||||||
|
cartSvcAddr string
|
||||||
|
currencySvcAddr string
|
||||||
|
shippingSvcAddr string
|
||||||
|
emailSvcAddr string
|
||||||
|
paymentSvcAddr string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
port := listenPort
|
||||||
|
if os.Getenv("PORT") != "" {
|
||||||
|
port = os.Getenv("PORT")
|
||||||
|
}
|
||||||
|
|
||||||
|
svc := new(checkoutService)
|
||||||
|
mustMapEnv(&svc.productCatalogSvcAddr, "PRODUCT_CATALOG_SERVICE_ADDR")
|
||||||
|
mustMapEnv(&svc.cartSvcAddr, "CART_SERVICE_ADDR")
|
||||||
|
mustMapEnv(&svc.currencySvcAddr, "CURRENCY_SERVICE_ADDR")
|
||||||
|
mustMapEnv(&svc.shippingSvcAddr, "SHIPPING_SERVICE_ADDR")
|
||||||
|
mustMapEnv(&svc.emailSvcAddr, "EMAIL_SERVICE_ADDR")
|
||||||
|
mustMapEnv(&svc.paymentSvcAddr, "PAYMENT_SERVICE_ADDR")
|
||||||
|
|
||||||
|
log.Printf("starting to listen on tcp/%s", port)
|
||||||
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
srv := grpc.NewServer()
|
||||||
|
pb.RegisterCheckoutServiceServer(srv, svc)
|
||||||
|
log.Println("starting to listen on tcp: %q", lis.Addr().String())
|
||||||
|
log.Fatal(srv.Serve(lis))
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustMapEnv(target *string, envKey string) {
|
||||||
|
v := os.Getenv(envKey)
|
||||||
|
if v == "" {
|
||||||
|
panic(fmt.Sprintf("environment variable %q not set", envKey))
|
||||||
|
}
|
||||||
|
*target = v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *checkoutService) CreateOrder(ctx context.Context, req *pb.CreateOrderRequest) (*pb.CreateOrderResponse, error) {
|
||||||
|
log.Printf("[CreateOrder] user_id=%q user_currency=%q", req.UserId, req.UserCurrency)
|
||||||
|
resp := new(pb.CreateOrderResponse)
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderRequest) (*pb.PlaceOrderResponse, error) {
|
||||||
|
log.Printf("[PlaceOrder] user_id=%q user_currency=%q", req.UserId, req.UserCurrency)
|
||||||
|
resp := new(pb.PlaceOrderResponse)
|
||||||
|
return resp, nil
|
||||||
|
}
|
Loading…
Reference in a new issue