shorty-go

command module
v0.0.0-...-b5a54de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: MIT Imports: 10 Imported by: 0

README

Shortens URLs like bit.ly written in Go

A microservice used to shorten URLs built with Go.

This project was built using Echo and offers the option between two data stores:

  • Badger - Embedded Go Key/Value Database as a single standalone executable. Great for light / mid-tier usage.
  • Mongo + 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 is shorty. The web app is built with Vue.js. The source is found in the web-client directory.

GET /admin

See notes web-client/README.md for instructions on running and building the web app.

API

The API is pretty simple.

Authentication required - uri?key=:authKey

POST    /shorten                    body{ url:String }
GET     /links?l=:limit&s=:skip     (Mongo works, Badger in progress)
GET     /links/:code
DELETE  /links/:code

No 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 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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL