You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Max Schmitt 228bea54b0 Updated README.md for the new configuration 8 years ago
.vscode Initial commit 8 years ago
handlers Updated README.md for the new configuration 8 years ago
static - updated handleInfo and handleAccess to the gin framework 8 years ago
store Switched configuration to Yaml 8 years ago
.gitignore Added debug file from vscode and .db.lock from bolt db to gitignore 8 years ago
.travis.yml fixed typos, cleaned up 8 years ago
LICENSE.md - Added LICENSE.md 8 years ago
README.md Updated README.md for the new configuration 8 years ago
config.yml Updated README.md for the new configuration 8 years ago
docker-compose.yml fixed naming to URL Shortener 8 years ago
main.go Switched configuration to Yaml 8 years ago
run.sh Initial commit 8 years ago

README.md

Golang URL Shortener

Build Status GoDoc Go Report Card Coverage Status License

Main Features:

  • URL Shortening
  • Visitor Counting
  • URL deletion
  • Authorization System
  • High performance database with bolt
  • ShareX integration
  • Easy Docker Deployment

Server Installation

Standard

Since we don't provide prebuild binaries, you have to build it yourself. For that you need Golang and Git installed on your system.

git clone https://github.com/maxibanki/golang-url-shortener # Clone repository
cd golang-url-shortener                                     # Go into it
go get -v ./...                                             # Fetch dependencies
go build                                                    # Build executable
./golang-url-shortener                                      # Run it

Docker Compose

Only execute the docker-compose.yml and adjust the environment variables to your needs.

Configuration:

The configuration is a yaml based file of key value pairs. the default configuration file looks like that:

DBPath: main.db    # Location of the bolt DB database
ListenAddr: :8080  # RemoteAddr of the http server. (IP:Port)
ShortedIDLength: 4 # Length of the random generated ID

Clients:

General

There is a mechanism integrated, that you can call the POST endpoints with the following techniques:

  • application/json
  • application/x-www-form-urlencoded
  • multipart/form-data

ShareX Configuration

This URL Shortener has fully support with ShareX. To use it, just import the configuration to your ShareX. For that you need to open the Destination settings => Other / Custom uploaders => Import => From Clipboard menu.

After you've done this, you need to set it as your standard URL Shortener. For that go back into your main menu => Destinations => URL Shortener => Custom URL Shortener.

{
  "Name": "Golang URL Shortener",
  "DestinationType": "URLShortener",
  "RequestType": "POST",
  "RequestURL": "http://127.0.0.1:8080/api/v1/create",
  "Arguments": {
    "URL": "$input$"
  },
  "ResponseType": "Text",
  "URL": "$json:URL$"
}

Curl

Create

curl -X POST -H 'Content-Type: application/json' -d '{"URL":"https://www.google.de/"}' http://127.0.0.1:8080/api/v1/create
{
    "URL": "http://127.0.0.1:8080/dgUV",
}

Info

$ curl -X POST -H 'Content-Type: application/json' -d '{"ID":"dgUV"}' http://127.0.0.1:8080/api/v1/info
{
    "URL": "https://google.com/",
    "VisitCount": 1,
    "CreatedOn": "2017-10-29T23:35:48.2977548+01:00",
    "LastVisit": "2017-10-29T23:36:14.193236+01:00"
}

HTTP Endpoints:

/api/v1/create POST

Create is the handler for creating entries, you need to provide only an URL. The response will always be JSON encoded and contain an URL with the short link.

/api/v1/info POST

This handler returns the information about an entry. This includes:

  • Created At
  • Last Visit
  • Visitor counter

For that you need to send a field ID to the backend.

TODO

Next changes sorted by priority

  • Fix handler unit tests
  • Switch configuration to Yaml
  • Add Authorization (oAuth2 e.g. Google)
  • Add Deletion functionality (depends on the authorization)
  • Performance optimization
  • Add ability to track the visitors (Referrer, maybe also live)
  • Test docker-compose installation
  • Provide image on the docker hub