Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(productcatalogservice): use //go:embed directive for products.json #1361

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/productcatalogservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ FROM alpine AS release

WORKDIR /usr/src/app/

COPY ./src/productcatalogservice/products.json ./
COPY --from=builder /go/bin/productcatalogservice/ ./

EXPOSE ${PRODUCT_SERVICE_PORT}
Expand Down
12 changes: 5 additions & 7 deletions src/productcatalogservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package main

import (
"context"
_ "embed"
"fmt"
"go.opentelemetry.io/otel/sdk/instrumentation"
"io/ioutil"
"net"
"os"
"strings"
Expand Down Expand Up @@ -50,6 +50,9 @@ var (
initResourcesOnce sync.Once
)

//go:embed products.json
var products []byte

func init() {
log = logrus.New()
catalog = readCatalogFile()
Expand Down Expand Up @@ -157,13 +160,8 @@ type productCatalog struct {
}

func readCatalogFile() []*pb.Product {
catalogJSON, err := ioutil.ReadFile("products.json")
if err != nil {
log.Fatalf("Reading Catalog File: %v", err)
}

var res pb.ListProductsResponse
if err := protojson.Unmarshal(catalogJSON, &res); err != nil {
if err := protojson.Unmarshal(products, &res); err != nil {
log.Fatalf("Parsing Catalog JSON: %v", err)
}

Expand Down
Loading