Skip to content

Instantly share code, notes, and snippets.

View mhmxs's full-sized avatar
🏠
Working from home

Richard Kovacs mhmxs

🏠
Working from home
View GitHub Profile
#cloud-config
write_files:
- path: /etc/environment
content: |
DOCKER_CLI_EXPERIMENTAL="enabled"
DOCKER_BUILDKIT=1
EDITOR=vim
append: true
- path: /etc/docker/daemon.json
content: |
#!/usr/bin/env zsh
# vim: ts=2 sw=2
export AUTOENV_IN_FILE=".env"
export AUTOENV_OUT_FILE="~/.bashrc"
if [[ -z "$AUTOENV_AUTH_FILE" ]]; then
AUTOENV_AUTH_FILE=~/.autoenv_authorized
fi
# Custom zsh plugin called gopath
gopath() {
: ${1?=GOROOT required}
: ${2?=GOPATH required}
cat > ~/.gopath <<EOF
export GOROOT=$1
export GOPATH=$2
export PATH="$1/bin:$2/bin:\$ORIGINAL_PATH"
EOF
@kubernetes:Deployment {
image: "exchange-simple:v.1.0",
dockerHost: "tcp://192.168.99.100:2376",
dockerCertPath: "/Users/mhmxs/.minikube/certs"
}
@http:ServiceConfig {
basePath: "/exchangeSimple"
}
@kubernetes:Service {
serviceType: "NodePort"
import ballerina/http;
import ballerina/io;
http:Client simpleEndpoint = new("http://localhost:9091/exchangeSimple/getRate");
http:Client enterpriseEndpoint = new("http://localhost:9092/exchangeEnterprise/getRate", config = {
retryConfig: {
interval: 3000,
count: 2,
backOffFactor: 2.0,
maxWaitInterval: 20000
import ballerina/http;
type Operand "+"|"-"|"*"|"/";
type Operation record {
float leftSide = 0;
float rightSide = 0;
Operand operand?;
!...
};
type Response record {
string currency;
float rate;
string description?;
};
type Handler object {
private Exchanger e = new;
function generateResponse(http:Request request) returns json|error;
service exchangeEnterprise on new http:Listener(9092) {
private Handler handler = new;
resource function getRate(http:Caller caller, http:Request request) {
json|error message = self.handler.generateResponse(request);
http:Response response = new;
if (message is json) {
response.setJsonPayload(message);
} else {
type CurrencyNotFoundError error<string>;
type Exchanger object {
private map<float> currencies;
function __init() {
map<float> currencies = {
USD: 34.80,
EUR: 35.70,
GBP: 32.00
function generateResponse(string|error payload) returns @untainted json {
return payload is string
? { currency: payload, rate: getExchangeRate(payload) }
: { "error": string `Invalid currency: {{payload.reason()}}` };
}
function getExchangeRate(string currency) returns float {
match currency {
"USD"|"EUR" => return 35.50;
"GBP" => return 32.00;