https://github.com/theantichris/url-shortener
A URL shortener written in Go.
https://github.com/theantichris/url-shortener
go golang hexagonal-architecture json message-pack mongodb msgpack redis
Last synced: 5 months ago
JSON representation
A URL shortener written in Go.
- Host: GitHub
- URL: https://github.com/theantichris/url-shortener
- Owner: theantichris
- License: mit
- Created: 2020-09-15T19:31:31.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-10-22T11:36:31.000Z (over 5 years ago)
- Last Synced: 2025-06-02T16:41:47.026Z (about 1 year ago)
- Topics: go, golang, hexagonal-architecture, json, message-pack, mongodb, msgpack, redis
- Language: Go
- Homepage:
- Size: 72.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# url-shortener
 [](https://pkg.go.dev/github.com/theantichris/url-shortener)
A URL shortener written in Go.
## Available Ports & Adaptors
### Repositories
* MongoDB
* Redis
### Serializers
* JSON
* MessagePack
## Development
1. Start Mongo and Redis servers
* `docker-compose up`
* For Mongo add the `redirects` collection
* Mongo Express is accessible at `http://localhost:8081`
1. Copy `sample.env` to `.env` and update values
* Set `DB_TYPE` to `mongo` or `redis`
1. Start the application
* `go run main.go`
* The application is accessible at `http://localhost:8080`
## Endpoints
### GET /
A health check endpoint that displays a message if the server is running.
### POST /
Creates a new redirect and returns the code.
#### Body
```json
{
"url": "http:/example.com"
}
```
#### Response
```json
{
"code": "Rz5x645Mg",
"url": "https://example.com",
"created_at": 1602164689
}
```
### GET /{code}
Redirects you to the URL for the specified code.