Coder Social home page Coder Social logo

shawty's Introduction

GoDoc license

Shawty: URL Shortener Service

This service encodes URL in base-36 and store them in filesystem.

It has 3 features: shorten, unshorten, and redirect.

Can I use it in production?

You need to implement a storage that can scale beyond one application server.

Why?

By itself, URL shortening is quite useful.

But this project exists to demonstrate:

  • How concise Go is. cloc shows that this project contains only 125 lines.

  • How slim Go is: 3MB RAM.

  • How comprehensive Go standard library is.

  • How easy it is to get up and running in Go. It took me about 1 hour from start to finish. Writing this README file took longer time.

  • How performant Go is:

    # Command  : ab -n 100000 -c 200 -k http://localhost:8080/dec/1
    # Processor: 2.26 GHz Intel Core 2 Duo  <-- Crummy 6 years old laptop
    
    Concurrency Level:      200
    Time taken for tests:   8.610 seconds
    Complete requests:      100000
    Failed requests:        0
    Non-2xx responses:      100000
    Keep-Alive requests:    100000
    Total transferred:      22400000 bytes
    HTML transferred:       7600000 bytes
    Requests per second:    11614.80 [#/sec] (mean)
    Time per request:       17.219 [ms] (mean)
    Time per request:       0.086 [ms] (mean, across all concurrent requests)
    Transfer rate:          2540.74 [Kbytes/sec] received
    

My other Go libraries

  • Tollbooth: Simple middleware to rate-limit HTTP requests.

  • Gomet: Simple HTTP client & server long poll library for Go. Useful for receiving live updates without needing Websocket.

  • Stopwatch: A small library to measure latency of things. Useful if you want to report latency data to Graphite.

  • LaborUnion: A dynamic worker pool library.

shawty's People

Contributors

amerine avatar didip avatar skinp avatar tanerax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

shawty's Issues

Drop Gorilla mux

For simple pattern matching like this, you don't necessarily need a router like mux. You can give a tree prefix like /red/ (note the trailing slash) to DefaultServeMux (e.g. by calling http.HandleFunc). And if you really wanted to make this short, you could inline the handler functions — although that would trade off some readability.

So, this:

params := mux.Vars(r)
code := params["code"]

…could simply become:

code := r.URL.Path[len("/red/"):]

Plus, you have some inconsistency with that, at another place you write code := mux.Vars(r)["code"] on one line.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.