fix go builds after deleting pkg internal

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2018-07-10 20:11:30 -07:00
parent dff246a3d7
commit 61cf05844d
13 changed files with 56 additions and 57 deletions

View file

@ -8,7 +8,7 @@ RUN go build -o /cartservice_probe .
# cartservice # cartservice
FROM gcr.io/google-appengine/aspnetcore:2.1.0 FROM gcr.io/google-appengine/aspnetcore:2.1.0
COPY --from=builder /cartservice_probe /cartservice_probe COPY --from=builder /cartservice_probe /cartservice_probe
RUN apt update && apt install net-tools telnet RUN apt-get update && apt-get install net-tools telnet
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN dotnet restore && \ RUN dotnet restore && \

View file

@ -6,10 +6,9 @@ import (
"os" "os"
"time" "time"
"microservices-demo/src/internal"
pb "./genproto" pb "./genproto"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -24,7 +23,8 @@ func main() {
"127.0.0.1:"+port, "127.0.0.1:"+port,
grpc.WithBlock(), grpc.WithBlock(),
grpc.WithTimeout(time.Second*3), grpc.WithTimeout(time.Second*3),
internal.DefaultDialOptions(), grpc.WithInsecure(),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
) )
if err != nil { if err != nil {
log.Fatalf("probe failed: failed to connect: %+v", err) log.Fatalf("probe failed: failed to connect: %+v", err)

View file

@ -6,7 +6,8 @@ WORKDIR /go/src/checkoutservice
RUN go get -d github.com/google/uuid \ RUN go get -d github.com/google/uuid \
google.golang.org/grpc \ google.golang.org/grpc \
google.golang.org/grpc/codes \ google.golang.org/grpc/codes \
google.golang.org/grpc/status google.golang.org/grpc/status \
go.opencensus.io/plugin/ocgrpc
COPY . . COPY . .
# get remaining dependencies # get remaining dependencies
RUN go get -d ./... RUN go get -d ./...

View file

@ -7,9 +7,8 @@ import (
"net" "net"
"os" "os"
"microservices-demo/src/internal"
"github.com/google/uuid" "github.com/google/uuid"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -52,7 +51,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
srv := grpc.NewServer(internal.DefaultServerOptions()...) srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
pb.RegisterCheckoutServiceServer(srv, svc) pb.RegisterCheckoutServiceServer(srv, svc)
log.Printf("starting to listen on tcp: %q", lis.Addr().String()) log.Printf("starting to listen on tcp: %q", lis.Addr().String())
log.Fatal(srv.Serve(lis)) log.Fatal(srv.Serve(lis))
@ -149,7 +148,9 @@ func (cs *checkoutService) prepareOrderItemsAndShippingQuoteFromCart(ctx context
} }
func (cs *checkoutService) quoteShipping(ctx context.Context, address *pb.Address, items []*pb.CartItem) (*pb.Money, error) { func (cs *checkoutService) quoteShipping(ctx context.Context, address *pb.Address, items []*pb.CartItem) (*pb.Money, error) {
conn, err := grpc.DialContext(ctx, cs.shippingSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.shippingSvcAddr,
grpc.WithInsecure(),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect shipping service: %+v", err) return nil, fmt.Errorf("could not connect shipping service: %+v", err)
} }
@ -166,7 +167,7 @@ func (cs *checkoutService) quoteShipping(ctx context.Context, address *pb.Addres
} }
func (cs *checkoutService) getUserCart(ctx context.Context, userID string) ([]*pb.CartItem, error) { func (cs *checkoutService) getUserCart(ctx context.Context, userID string) ([]*pb.CartItem, error) {
conn, err := grpc.DialContext(ctx, cs.cartSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.cartSvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect cart service: %+v", err) return nil, fmt.Errorf("could not connect cart service: %+v", err)
} }
@ -180,7 +181,7 @@ func (cs *checkoutService) getUserCart(ctx context.Context, userID string) ([]*p
} }
func (cs *checkoutService) emptyUserCart(ctx context.Context, userID string) error { func (cs *checkoutService) emptyUserCart(ctx context.Context, userID string) error {
conn, err := grpc.DialContext(ctx, cs.cartSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.cartSvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return fmt.Errorf("could not connect cart service: %+v", err) return fmt.Errorf("could not connect cart service: %+v", err)
} }
@ -195,7 +196,7 @@ func (cs *checkoutService) emptyUserCart(ctx context.Context, userID string) err
func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartItem, userCurrency string) ([]*pb.OrderItem, error) { func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartItem, userCurrency string) ([]*pb.OrderItem, error) {
out := make([]*pb.OrderItem, len(items)) out := make([]*pb.OrderItem, len(items))
conn, err := grpc.DialContext(ctx, cs.productCatalogSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.productCatalogSvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect product catalog service: %+v", err) return nil, fmt.Errorf("could not connect product catalog service: %+v", err)
} }
@ -219,7 +220,7 @@ func (cs *checkoutService) prepOrderItems(ctx context.Context, items []*pb.CartI
} }
func (cs *checkoutService) convertCurrency(ctx context.Context, from *pb.Money, toCurrency string) (*pb.Money, error) { func (cs *checkoutService) convertCurrency(ctx context.Context, from *pb.Money, toCurrency string) (*pb.Money, error) {
conn, err := grpc.DialContext(ctx, cs.currencySvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.currencySvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect currency service: %+v", err) return nil, fmt.Errorf("could not connect currency service: %+v", err)
} }
@ -234,7 +235,7 @@ func (cs *checkoutService) convertCurrency(ctx context.Context, from *pb.Money,
} }
func (cs *checkoutService) chargeCard(ctx context.Context, amount *pb.Money, paymentInfo *pb.CreditCardInfo) (string, error) { func (cs *checkoutService) chargeCard(ctx context.Context, amount *pb.Money, paymentInfo *pb.CreditCardInfo) (string, error) {
conn, err := grpc.DialContext(ctx, cs.paymentSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.paymentSvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return "", fmt.Errorf("failed to connect payment service: %+v", err) return "", fmt.Errorf("failed to connect payment service: %+v", err)
} }
@ -250,7 +251,7 @@ func (cs *checkoutService) chargeCard(ctx context.Context, amount *pb.Money, pay
} }
func (cs *checkoutService) sendOrderConfirmation(ctx context.Context, email string, order *pb.OrderResult) error { func (cs *checkoutService) sendOrderConfirmation(ctx context.Context, email string, order *pb.OrderResult) error {
conn, err := grpc.DialContext(ctx, cs.emailSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.emailSvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return fmt.Errorf("failed to connect email service: %+v", err) return fmt.Errorf("failed to connect email service: %+v", err)
} }
@ -262,7 +263,7 @@ func (cs *checkoutService) sendOrderConfirmation(ctx context.Context, email stri
} }
func (cs *checkoutService) shipOrder(ctx context.Context, address *pb.Address, items []*pb.CartItem) (string, error) { func (cs *checkoutService) shipOrder(ctx context.Context, address *pb.Address, items []*pb.CartItem) (string, error) {
conn, err := grpc.DialContext(ctx, cs.shippingSvcAddr, internal.DefaultDialOptions()...) conn, err := grpc.DialContext(ctx, cs.shippingSvcAddr, grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return "", fmt.Errorf("failed to connect email service: %+v", err) return "", fmt.Errorf("failed to connect email service: %+v", err)
} }

View file

@ -9,7 +9,9 @@ RUN go get -d github.com/google/uuid \
github.com/sirupsen/logrus \ github.com/sirupsen/logrus \
google.golang.org/grpc \ google.golang.org/grpc \
google.golang.org/grpc/codes \ google.golang.org/grpc/codes \
google.golang.org/grpc/status google.golang.org/grpc/status \
go.opencensus.io/plugin/ochttp \
go.opencensus.io/plugin/ochttp/propagation/b3
# copy go-only part of the build # copy go-only part of the build
COPY *.go ./ COPY *.go ./

View file

@ -7,11 +7,10 @@ import (
"os" "os"
"time" "time"
"microservices-demo/src/internal"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/plugin/ochttp" "go.opencensus.io/plugin/ochttp"
"go.opencensus.io/plugin/ochttp/propagation/b3" "go.opencensus.io/plugin/ochttp/propagation/b3"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -117,7 +116,10 @@ func mustMapEnv(target *string, envKey string) {
func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) { func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) {
var err error var err error
*conn, err = grpc.DialContext(ctx, addr, grpc.WithTimeout(time.Second*3), internal.DefaultDialOptions()...) *conn, err = grpc.DialContext(ctx, addr,
grpc.WithInsecure(),
grpc.WithTimeout(time.Second*3),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
panic(errors.Wrapf(err, "grpc: failed to connect %s", addr)) panic(errors.Wrapf(err, "grpc: failed to connect %s", addr))
} }

View file

@ -1,17 +0,0 @@
package internal
import "google.golang.org/grpc"
import "go.opencensus.io/plugin/ocgrpc"
func DefaultDialOptions() []grpc.DialOption {
return []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
}
}
func DefaultServerOptions() []grpc.ServerOption {
return []grpc.ServerOption{
grpc.StatsHandler(&ocgrpc.ServerHandler{}),
}
}

View file

@ -6,7 +6,8 @@ WORKDIR /src/microservices-demo/productcatalogservice
# get known dependencies # get known dependencies
RUN go get -d google.golang.org/grpc \ RUN go get -d google.golang.org/grpc \
google.golang.org/grpc/codes \ google.golang.org/grpc/codes \
google.golang.org/grpc/status google.golang.org/grpc/status \
go.opencensus.io/plugin/ocgrpc
COPY . . COPY . .
# get remaining dependencies # get remaining dependencies

View file

@ -8,9 +8,8 @@ import (
"net" "net"
"strings" "strings"
"microservices-demo/src/internal"
pb "./genproto" pb "./genproto"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -95,7 +94,7 @@ func run(port int) string {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
srv := grpc.NewServer(internal.DefaultServerOptions()...) srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
pb.RegisterProductCatalogServiceServer(srv, &productCatalog{}) pb.RegisterProductCatalogServiceServer(srv, &productCatalog{})
go srv.Serve(l) go srv.Serve(l)
return l.Addr().String() return l.Addr().String()

View file

@ -2,12 +2,12 @@ package main
import ( import (
"context" "context"
"microservices-demo/src/internal"
"testing" "testing"
pb "./genproto" pb "./genproto"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -16,7 +16,9 @@ import (
func TestServer(t *testing.T) { func TestServer(t *testing.T) {
ctx := context.Background() ctx := context.Background()
addr := run(0) addr := run(0)
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -6,7 +6,9 @@ WORKDIR /src/microservices-demo/shippingservice
# get known dependencies # get known dependencies
RUN go get -d golang.org/x/net/context \ RUN go get -d golang.org/x/net/context \
google.golang.org/grpc \ google.golang.org/grpc \
google.golang.org/grpc/reflection google.golang.org/grpc/reflection \
go.opencensus.io/plugin/ocgrpc
COPY . . COPY . .
# get other dependencies # get other dependencies
RUN go get -d ./... RUN go get -d ./...

View file

@ -6,8 +6,7 @@ import (
"net" "net"
"os" "os"
"microservices-demo/src/internal" "go.opencensus.io/plugin/ocgrpc"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
@ -72,7 +71,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("failed to listen: %v", err) log.Fatalf("failed to listen: %v", err)
} }
s := grpc.NewServer(internal.DefaultServerOptions()...) s := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
pb.RegisterShippingServiceServer(s, &server{}) pb.RegisterShippingServiceServer(s, &server{})
log.Printf("Shipping Service listening on port %s", port) log.Printf("Shipping Service listening on port %s", port)

View file

@ -5,9 +5,8 @@ import (
"log" "log"
"os" "os"
"microservices-demo/src/internal"
pb "./genproto" pb "./genproto"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -72,7 +71,8 @@ func main() {
func testProductCatalogService() error { func testProductCatalogService() error {
addr := os.Getenv("PRODUCT_CATALOG_SERVICE_ADDR") addr := os.Getenv("PRODUCT_CATALOG_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }
@ -107,7 +107,8 @@ func testProductCatalogService() error {
func testShippingService() error { func testShippingService() error {
addr := os.Getenv("SHIPPING_SERVICE_ADDR") addr := os.Getenv("SHIPPING_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }
@ -153,7 +154,9 @@ func testShippingService() error {
func testRecommendationService() error { func testRecommendationService() error {
addr := os.Getenv("RECOMMENDATION_SERVICE_ADDR") addr := os.Getenv("RECOMMENDATION_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }
@ -175,7 +178,8 @@ func testRecommendationService() error {
func testPaymentService() error { func testPaymentService() error {
addr := os.Getenv("PAYMENT_SERVICE_ADDR") addr := os.Getenv("PAYMENT_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }
@ -203,7 +207,8 @@ func testPaymentService() error {
func testEmailService() error { func testEmailService() error {
addr := os.Getenv("EMAIL_SERVICE_ADDR") addr := os.Getenv("EMAIL_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }
@ -256,7 +261,8 @@ func testEmailService() error {
func testCurrencyService() error { func testCurrencyService() error {
addr := os.Getenv("CURRENCY_SERVICE_ADDR") addr := os.Getenv("CURRENCY_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }
@ -287,7 +293,8 @@ func testCurrencyService() error {
func testCartService() error { func testCartService() error {
addr := os.Getenv("CART_SERVICE_ADDR") addr := os.Getenv("CART_SERVICE_ADDR")
conn, err := grpc.Dial(addr, internal.DefaultDialOptions()) conn, err := grpc.Dial(addr,
grpc.WithInsecure(), grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
if err != nil { if err != nil {
return err return err
} }