forked from GoogleCloudPlatform/microservices-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ace Nassri
committed
Jun 22, 2018
1 parent
a1b141d
commit 28a6fbb
Showing
9 changed files
with
1,260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM node:8 | ||
WORKDIR /usr/src/app | ||
COPY package*.json ./ | ||
RUN npm install --only=production | ||
COPY . . | ||
EXPOSE 31337 | ||
CMD [ "node", "server.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* | ||
* Copyright 2015 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
const path = require('path'); | ||
const grpc = require('grpc'); | ||
|
||
const PROTO_PATH = path.join(__dirname, './proto/currency_service.proto'); | ||
const PORT = 31337; | ||
|
||
const shopProto = grpc.load(PROTO_PATH).hipstershop; | ||
const client = new shopProto.CurrencyService(`localhost:${PORT}`, | ||
grpc.credentials.createInsecure()); | ||
|
||
const request = { | ||
from: { | ||
currency_code: 'USD', | ||
amount: { | ||
decimal: 300, | ||
fractional: 0 | ||
} | ||
}, | ||
to_code: 'CHF' | ||
}; | ||
|
||
client.convert(request, function (err, response) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
const amount = response.amount; | ||
console.log(`OUTPUT: ${amount.decimal}.${amount.fractional}`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
syntax = "proto3"; | ||
package hipstershop; | ||
|
||
message Empty {} | ||
|
||
service CurrencyService { | ||
rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {} | ||
rpc Convert(CurrencyConversionRequest) returns (Money) {} | ||
} | ||
// Describes a money amount without currency. For example, decimal=2 and | ||
// fractional=500 (or fractional=5) makes up 2.5 units. | ||
message MoneyAmount { | ||
uint32 decimal = 1; | ||
uint32 fractional = 2; | ||
} | ||
message Money { | ||
// The 3-letter currency code defined in ISO 4217. | ||
string currency_code = 1; | ||
MoneyAmount amount = 2; | ||
} | ||
message GetSupportedCurrenciesResponse { | ||
// The 3-letter currency code defined in ISO 4217. | ||
repeated string currency_codes = 1; | ||
} | ||
message CurrencyConversionRequest { | ||
Money from = 1; | ||
// The 3-letter currency code defined in ISO 4217. | ||
string to_code = 2; | ||
} |
Oops, something went wrong.