siongui / go-kit-url-shortener-micro-service

URL shortener micro-service using Go kit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URL Shortener Microservice

https://goreportcard.com/badge/github.com/siongui/go-kit-url-shortener-micro-service

URL shortener microservice using Go kit, Docker, and Amazon EKS.

Development Environment:

Description

See Assignment.

Usage

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

Database Configuration

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.

Deployment

Deploy to Amazon EKS

UNLICENSE

Released in public domain. See UNLICENSE.

References

[1]
[2]
[3]Microservices in Go (Chinese translation)
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]
[12]

About

URL shortener micro-service using Go kit

License:The Unlicense


Languages

Language:Go 84.0%Language:Makefile 7.2%Language:HTML 6.6%Language:Dockerfile 2.3%