URL Shortener service in Go. Functionality:
- Create/Describe/Delete shortened urls
- Redirect shortened urls to Original
- Check statistic: redirections count, lastRedirectTime
https://app.swaggerhub.com/apis/vrazdalovschi/url-shortener/0.1.0-oas3
API docs are available by swagger (api/swagger.yaml). Just deploy using docker-compose:
http://localhost:8080/swaggerui/swagger.yaml
http://localhost:8080/swagger/index.html
Run with Docker (deployments folder)
cd deployments
docker-compose up -d --build
Project is developed in GO 1.14 an instance with go 1.14 is expected
Available using first flags if not set then env variable
HTTP_ADDR - Endpoint port (default value :8080)
DB_HOST - Database Host. Default: localhost
DB_PORT - Database Port. Default: 5432
DB_USER - Database User. Default: url-shortener
DB_PASSWORD - Database Password. Default: root
DB_NAME - Database Name. Default: shortener
Postgres is chosen for storage purposes.
Tables are auto created on starting the project.
CREATE TABLE IF NOT EXISTS url
(
shortenedid VARCHAR NOT NULL UNIQUE,
originalurl VARCHAR NOT NULL,
apikey VARCHAR NOT NULL,
creationtime TIMESTAMP NOT NULL,
expirationdate TIMESTAMP NOT NULL
);
CREATE TABLE IF NOT EXISTS stats
(
shortenedid VARCHAR NOT NULL UNIQUE,
redirects INTEGER DEFAULT 0,
visitdate TIMESTAMP
);
- Test Coverage
- Better error handling
- Distributed caching
- SQL Schema migration
Prometheus metrics:
- System load
- Latency summary per each api call (success/error)
- Counter for each api call (success/error)
http://localhost:8080/internal/metrics