Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roboncode/shorty-go
Microservice that shortens urls like bit.ly written in Go
https://github.com/roboncode/shorty-go
badgerdb go golang microservice mongodb url-shortener vuejs
Last synced: 3 months ago
JSON representation
Microservice that shortens urls like bit.ly written in Go
- Host: GitHub
- URL: https://github.com/roboncode/shorty-go
- Owner: roboncode
- License: mit
- Created: 2019-04-03T16:46:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-09T23:34:08.000Z (over 5 years ago)
- Last Synced: 2024-06-28T02:43:34.344Z (5 months ago)
- Topics: badgerdb, go, golang, microservice, mongodb, url-shortener, vuejs
- Language: Go
- Homepage:
- Size: 1.09 MB
- Stars: 36
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shortens URLs like bit.ly written in Go
A microservice used to shorten URLs built with Go.
This project was built using [Echo](https://echo.labstack.com/) and offers the option between two data stores:
* [Badger](https://github.com/dgraph-io/badger) - Embedded Go Key/Value Database as a single standalone executable. Great for light / mid-tier usage.
* [Mongo](https://github.com/mongodb/mongo-go-driver) + [go-cache](github.com/patrickmn/go-cache) - Allows for greater control of data storage and clustered environments.Microservice runs on http://localhost:8080 by default.
### Getting started
```
cd $GOPATH
go get github.com/roboncode/shorty-go
cd github.com/roboncode/shorty-go
dep ensure# To run with BadgerDb
go run main.go# To run with MongoDb
make mongo
STORE=mongo go run main.go
```### Running standalone executable
Give the code a quick spin by building a single exec with no external dependencies. Optional config.yaml file can be used for configuration or you can configure it as part of the command line.
```
make standalone# Run with BadgerDb
# Run on Linux
make run
# Run on Mac OSX
make run_osx
# Run on Windows
make run_win# Startup MongoDb instance
make mongo
# Run on Linux
STORE=mongo make run
# Run on Mac OSX
STORE=mongo make run_osx
# Run on Windows
STORE=mongo make run_win
```### Running as Docker container
```
make build
make start
```### Running development
```
# Run with BadgerDb
make dev# Run with MongoDb
make mongo
STORE=mongo make dev
```### Running tests
```
make test
```### Admin Single Page Application (SPA)
The default API key in [config.yaml](config.yaml) is `shorty`. The web app is built with [Vue.js](https://github.com/vuejs/vue). The source is
found in the [web-client](web-client) directory.```
GET /admin
```> See notes [web-client/README.md](web-client/README.md) for instructions on running and building the web app.
### API
The API is pretty simple.
```
Authentication required - uri?key=:authKeyPOST /shorten body{ url:String }
GET /links?l=:limit&s=:skip (Mongo works, Badger in progress)
GET /links/:code
DELETE /links/:codeNo Authentication required
GET /admin Admin SPA
GET / Landing page
GET /:code Redirect to long url
GET /* 404 page
```### Config and Env variables
Shorty uses [Viper](https://github.com/spf13/viper) to handle configuration. The `config.yaml` contains all the
configurable variables and default values. You can also override any variables as environment variables. You will see examples of this
in the `docker-compose.yml`. You can also set the variables from the command line.```
ENV=prod STORE=mongo ./bin/shorty
```Feel free to fork it, hack it and use it any way you please.
**MIT License**