andradeandrey / goshort

Golang URL Shortener

Home Page:http://s.h0rt.me/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoShort

Build Status Go Report Card

GoShort is a simple Golang API URL Shortener, started as a learning project it gave me a nice time building the first version, I'll try to update it often with new ideas and functionality, one of the things I wanna do first is use Redis + MySQL to balance the load of the current MySQL database, the second thing I wanna do is restructure the files in order to make it easier to mantain. Hope you people like this and I'm open to new ideas, just remember this is just the server part, the client will be public soon, some tutorial will be public soon on my blog this project's now on the second version, I now restructured all the code and I laid the foundations to new cool features, I´ll try to add user registration and IP throttle in order to expand this tool use and functionality.

Setup

  • Install dependencies: go get -u ./...

  • Go to config/local.yml and set up your required info

    • db_type: "postgres" if you don't set this up it will fall back to mysql
    • dsn: "user:pass@tcp(127.0.0.1)/goshort?charset=utf8&parseTime=true&loc=Local" it needs to a be a valid DSN, this example is based on a mysql connection where 127.0.0.1 is the host.
    • jwt_signing_key: "RandomHS256-HMAC_JWTKey" this is needed in order to work.
  • Copy .env.example and save it as .env

  • Edit .env file with your PORT and DATABASE_URL info`

  • Install VueJS dependencies: npm install

  • Compile frontend: npm run build

  • Build: go build cmd/server/main.go -o goshortyou can user whichever name you want, remember using .exe if you're building this for Windows systems.

  • Run the server: ./goshortAgain, .exe if you're using Windows.

API

Currently has just two basic functions, search the original URL by a given code and store new URL's randomly generating unique codes.

Get the original URL

GET /:code

This code is used to redirect to original URL, if not found shows a 404 Page.

Submit a URL to shorten

POST /v1/links

Body:

{
    "url": "https://www.example.com/lets-see-if-this-works"
}

Returns:

  {
    "url": {
        "code": "pJ7V",
        "original_url": "https://www.example.com/lets-see-if-this-works",
        "created_at":  "2021-04-13T06:33:47.112707Z"
    }
}

TO DO

  • Make the redirection in the main route
  • Make a delete route
  • Make guest and member URL's
  • Make a route to fetch all the member URL's
  • Social login
  • Make GoShort client with VueJS
  • Implement Redis to search by code
  • Implement visit count
  • Implement QR Code
  • Visual changes (add brand)
  • Implement local storage history to guests
  • Implement throttle by IP
  • Add LICENSE
  • Add CHANGELOG.md
  • Add CI/CD to the workflow

Compatibility

The project frontend is built with VueJS, that means ES6 syntax is the standard used, some browsers may not be compliant to this standard yet, thus some issues may arise, we've been notified about a bug happening in iPhone 6s with Safari, following that trace we find the same issue in IE11, we've managed to fix IE11 issue but couldn't reproduce the issue in iPhone 6s yet.

This issue may be found (or not) in browsers not fully compliant with ECMAScript 2015 (ES6), we added babel-polyfill to handle this issue but we cannot guarantee that the problem will not arise again in older browsers.

Thanks to Yan Edy Chota Castillo who first encountered this bug in production!

Changelog

You can see all our realeases in the changelog

About

Golang URL Shortener

http://s.h0rt.me/

License:MIT License


Languages

Language:Go 72.0%Language:Vue 12.1%Language:JavaScript 6.5%Language:SCSS 3.8%Language:Makefile 3.5%Language:Dockerfile 1.1%Language:HTML 0.5%Language:Shell 0.5%