URL shortener microservice using Go kit, Docker, and Amazon EKS.
Development Environment:
See Assignment.
First install Docker Engine
and Docker Compose.
To run the micro-service in Docker environment:
$ sudo docker-compose up --build
To create short URL:
$ curl -XPOST -d'{"url":"https://github.com/siongui/go-kit-url-shortener-micro-service"}' localhost:8080/create
{"short_url":"20wogJaCuRtH0U5p60LvjZoVwsz"}
To recover the original URL:
$ curl -XGET localhost:8080/20wogJaCuRtH0U5p60LvjZoVwsz
{"url":"https://github.com/siongui/go-kit-url-shortener-micro-service"}
If you HTTP GET some URL that does not exist, you will get:
$ curl -XGET localhost:8080/20wogJaCuRtH0U5p
{"url":"","err":"sql: no rows in result set"}
To see metrics of the the micro-service:
$ curl -XGET localhost:8080/metrics
The application will determine which database to use according to environment variables. The application first check if the following environment variables are set:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_HOST
- POSTGRES_PORT
- POSTGRES_DB
If they are set, The application will try to connect to PostgresSQL. If connection failure, the application will panic. If the POSTGRES env are not set, the application will then check the following environment variable:
- SQLITE_DSN
If it is set, the application will try to connect to SQLite, panic if connection failure.
If all above environment variables are not set, the application will use SQLite
with file::memory:?cache=shared
DSN. See getds.go for details.
Released in public domain. See UNLICENSE.
[1] |
[2] |
[3] | Microservices in Go (Chinese translation) |
[4] |
[5] |
[6] |
[7] |
[8] |
[9] |
[10] |
[11] |
[12] |