Birthdays is a web service that stores the birthday date of users and calculates the remaining days until the user's birthday.

Birthdays is a web service that stores the birthday date of users and calculates the remaining days until the user's birthday.

Features

  • Metrics service exposes both service usage and system status
  • Custom listen ports for Birthdays service and Metrics service
  • Custom limit of concurrent request handlers
  • Custom timeout
  • Pluggable persistence modules
  • Settings via command line arguments or environment variables (BIRTHDAYS_ prefix)

Functionality

This application exploses the following HTTP-based APIs:

Description: Saves/updates the given user’s name and date of birth in the database.
Request: PUT /hello/<username> { “dateOfBirth”: “YYYY-MM-DD” }
Response: 204 No Content
Description: Returns hello birthday message for the given user
Request: Get /hello/<username>
Response: 200 OK
Response Examples:
A. If username’s birthday is in N days:
{ “message”: “Hello, <username>! Your birthday is in N day(s)”}
B. If username’s birthday is today:
{ “message”: “Hello, <username>! Happy birthday!” }

Prometheus metrics available via endpoint /metrics:${BIRTHDAYS_Metrics} (default BIRTHDAYS_Metrics port 9095)

Architecture

Birthdays deployed in a Kubernetes Cluster: Flow Diagram

Table of Contents

Build and run Birthdays

Requirements:

Compile and install:

$ go clean . && go build .

Run Unit Tests:

$ go clean . && go test . -v

Start Birthdays service:

$ ./birthdays

Birthdays service settings:

$ ./birthdays --help

Usage: birthdays [FLAG]...

Flags:
    --listen                 Service listen address.                                 (type: string; env: BIRTHDAYS_Listen; default: :8080)
    --workers                Number of serving workers.                              (type: uint8; env: BIRTHDAYS_Workers; default: 2)
    --timeout                Maximum time (in milliseconds) to wait for a worker.    (type: uint64; env: BIRTHDAYS_Timeout; default: 1000)
    --metrics                Metrics listen address.                                 (type: string; env: BIRTHDAYS_Metrics; default: :9095)
    --persistence-plugin     Persistence plugin                                      (type: string; env: BIRTHDAYS_PersistencePlugin; default: persistence_etcd.so)
    --persistence-options    Persistence options                                     (type: string; env: BIRTHDAYS_PersistenceOptions; default: { "endpoints": "localhost:2379", "path": "/users" })
    -h, --help               show help                                               (type: bool)

Build docker images

This builds the docker image xboshy/birthdays:0.1.0 using a multi-stage build

$ docker build -t xboshy/birthdays:0.1.0 .

Launching a container

$ docker run -e BIRTHDAYS_Listen=8080 -e BIRTHDAYS_Metrics=9095 -e BIRTHDAYS_PersistenceOptions='{ "endpoints": "etcd.host:2379", "path": "/users" }' -p 8080:8080 -p 9095:9095 xboshy/birthdays:0.1.0

Simple request scripts

$ ./tools/put.sh <birthdays-service-address> <username> <dateOfBirth>
$ ./tools/get.sh <birthdays-service-address> <username>

Examples:

$ ./tools/put.sh http://172.18.255.1:8080/hello revolut '2015-07-01'
*   Trying 172.18.255.1:8080...
* Connected to 172.18.255.1 (172.18.255.1) port 8080 (#0)
> PUT /hello/revolut HTTP/1.1
> Host: 172.18.255.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 29
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< Date: Sun, 15 Oct 2021 20:30:37 GMT
< 
* Connection #0 to host 172.18.255.1 left intact
./tools/get.sh http://172.18.255.1:8080/hello xboshy

*   Trying 172.18.255.1:8080...
* Connected to 172.18.255.1 (172.18.255.1) port 8080 (#0)
> GET /hello/revolut HTTP/1.1
> Host: 172.18.255.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Sun, 15 Oct 2021 20:30:46 GMT
< Content-Length: 63
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host 172.18.255.1 left intact
{ "message": "Hello, revolut! Your birthday is in 259 day(s)" }

Kubernetes deployment

Image should be available in your cluster.

Kind example:

kind load docker-image xboshy/birthdays:0.1.0

Deploying the Birthdays service:

# skip etcd deployment if you prefer to use an already existing etcd cluster
# you you skip etcd deployment, reflect the etcd configuration on deployment/birthdays.yaml
kubectl apply -f deployment/etcd.yaml
kubectl apply -f deployment/birthdays.yaml

Deploying the Prometheus with service discovery:

kubectl apply -f deployment/prometheus-rbac.yaml
kubectl apply -f deployment/prometheus.yaml

AWS EKS deployment

[Optional] Use eksctl for cluster deploying:

ssh-keygen -t rsa -b 4096 -f aws-eks-key
eksctl create cluster --config-file deployment/aws-eks-cluster.yaml

With aws-cli and eksctl installed, use the same deployment steps described in Kubernetes deployment.

Similar Resources

Web terminal - A (unsafe) technical demo to export a shell to web browser

Web terminal - A (unsafe) technical demo to export a shell to web browser

Web Terminal A (unsafe) technical demo to export a shell to web browser. This pr

Dec 27, 2022

Go-web-scaffold - A simple scaffold for building web app quickly

Go-web-scaffold A simple scaffold for building web app quickly. features This sc

Jan 21, 2022

Simple Bank is a simple REST API that allows users to perform transferences with each other.

Simple Bank is a simple REST API that allows users to perform transferences with each other. 🔧 Technologies Golang Docker PostgreSQ

Feb 15, 2022

A web forum built in Golang and SQLite and designed in SCSS

A web forum built in Golang and SQLite and designed in SCSS

Forum "Fairfax" 👉 What is it? A web forum built in Golang and SQLite and designed in SCSS. Members of the forum can take a personality test and be so

Nov 10, 2021

Automated penetration and auxiliary systems, providing XSS, XXE, DNS log, SSRF, RCE, web netcat and other Servers,gin-vue-admin

Automated penetration and auxiliary systems, providing XSS, XXE, DNS log, SSRF, RCE, web netcat and other Servers,gin-vue-admin

Simple DNS log Server,easy to ACME DNS challenge log easy send to elasticsearch https://github.com/hktalent/DNS_Server go4Hacker Automated penetration

Dec 30, 2022

A webpage bookmarking and snapshotting service

Omnom A webpage bookmarking and snapshotting service. Omnom is a rebooted implementation of @stef's original omnom project, big thanks for it.

Nov 22, 2022

GoTrue is a small open-source API written in Golang, that can act as a self-standing API service for handling user registration and authentication for Jamstack projects.

GoTrue is a small open-source API written in Golang, that can act as a self-standing API service for handling user registration and authentication for Jamstack projects.

GoTrue is a small open-source API written in Golang, that can act as a self-standing API service for handling user registration and authentication for Jamstack projects.

Dec 13, 2021

An inventory service for managing farming vehicles, equipment, and resources

An inventory service for managing farming vehicles, equipment, and resources

Inventory 📦 An inventory service for managing farming vehicles, equipment, and resources. What is this? A REST API for managing farm inventory via HT

Apr 29, 2022

Build a TodoList with Go Design and implement a backend RESTful service in golang with CRUD

May we ask Igor to do a little project in leu of sample code? If there is a hire, the hours spent should be invoiced, so please keep track of that. Th

May 5, 2022
log4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web servicelog4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web service
log4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web servicelog4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web service

log4jScanner Goals This tool provides you with the ability to scan internal (only) subnets for vulnerable log4j web services. It will attempt to send

Jan 5, 2023
Users API Service
Users API Service

bookstore_users-api Users API Service Overview This application handles users. Project Structure This project was written in golang, designed to use M

Feb 12, 2022
This service finds and — if necessary — generates icons for web sites
This service finds and — if necessary — generates icons for web sites

favicon-service (besticon) This is a favicon service: Supports favicon.ico and apple-touch-icon.png Simple URL API Fallback icon generation Docker ima

Nov 2, 2021
Go-service-gin - Simple Web api application developed in Golang and Gin

Simple Web api application developed in Golang and Gin Initial Tutorial URL http

Jan 4, 2022
A simple file-based service to stand in for the remote-service proxy on Apigee.

Apigee-Remote-Service-File A simple file-based service to stand in for the remote-service proxy on Apigee. All configuration is done locally in a YAML

Nov 3, 2021
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

Oct 10, 2021
GoatCounter is an open source web analytics platform available as a hosted service or self-hosted app

GoatCounter is an open source web analytics platform available as a hosted service (free for non-commercial use) or self-hosted app. It aims to offer easy to use and meaningful privacy-friendly web analytics as an alternative to Google Analytics or Matomo.

Dec 29, 2022
A social media API to handle users and their posts, written from scratch in Golang
A social media API to handle users and their posts, written from scratch in Golang

Initial Set-Up To start the project on your own machine you'll need Golang instlled, along with mongoDB. Once you've insured these requirements are me

Oct 9, 2021
Extract structured data from web sites. Web sites scraping.
Extract structured data from web sites. Web sites scraping.

Dataflow kit Dataflow kit ("DFK") is a Web Scraping framework for Gophers. It extracts data from web pages, following the specified CSS Selectors. You

Jan 7, 2023
記帳-PWA-web-app (Bookkeeping-PWA-web-app)
記帳-PWA-web-app (Bookkeeping-PWA-web-app)

GoKeep (bookkeeping web app) 記帳-PWA-web-app (Bookkeeping-PWA-web-app) demo link : https://bookkepping.herokuapp.com/ 測試用帳密 : tester002 , tester002 (亦可

Jan 31, 2022