Giter Club home page Giter Club logo

kurz.go's Introduction

kurz.go

kurz.go fork with some additional parameters (EventId, UserId, URL type) and extended API

https://raw.github.com/miha-stopar/kurz.go/master/kurzgo.png

See client directory for sample Python clients:

  • shorten:
import requests
import urllib
import urllib2

url = "http://localhost:9999/shorten/"
link = "https://github.com/"
typ = "attend"
data = {"url" : link, "user" : str(105), "eventid":"23", "type":typ}
enc_data = urllib.urlencode(data)
u = urllib2.urlopen(url, enc_data)
print u.read()
  • user stats:
import requests
import urllib
import urllib2
import json

url = "http://localhost:9999/user/"
uid = str(105)
print "user id: %s" % uid
data = {"id" : uid}
enc_data = urllib.urlencode(data)
u = urllib2.urlopen(url, enc_data)
j = u.read()
js = json.loads(j)
print js
# prints out:
# user id: 105
#{u'attends': {u'https://github.com/4': 1}, u'invites': {}, u'shares': {u'https://github.com/5': 4}}
  • event stats:
import requests
import urllib
import urllib2
import json

eid = str("23")
print "event id: %s" % eid
data = {"eventid" : eid}
enc_data = urllib.urlencode(data)
eurl = "http://localhost:9999/event/"
u = urllib2.urlopen(eurl, enc_data)
j = u.read()
js = json.loads(j)
print js
# prints out:
#{u'invitesCount': 1, u'invitesClicks': 3, u'sharesCount': 0, u'attendsCount': 1, u'attendsClicks': 1, u'sharesClicks': 0}

kurz.go - a url shortener in go

kurz.go is my attempt to write a program that is actually useful in go. Right now it is in beta stage.

Right now it can shorten URLs, redirect and list the latest stored URLs. All urls are stored in a redis (http://redis.io) instance.

Compiling kurz.go

Next to having a full install of go itself, kurz.go requires gorilla.mux, godis and simpleconfig to be installed. For installing go itself, please follow the fine instructions at http://golang.org

For installing gorilla/mux do:

$ go get code.google.com/p/gorilla/mux

for installing godis do:

$ go get github.com/simonz05/godis/redis

for installing simpleconfig do:

$ go get github.com/fs111/simpleconfig

Note: These modules will be installed into your $GOROOT, so make sure it is writable. Alternatively you can set $GOPATH and they will be installed there instead.

Once the dependecies are installed, check out kurz.go:
$ git clone https://github.com/fs111/kurz.go $ cd kurz.go $ make $ cd target $ usr/bin/kurz etc/kurz/kurz.conf #assumes that redis is up and running

In order to shorten a url POST it to http://localhost:9999/shorten/ with the parameter url set to the long url. In return, you will get a json document containing the long and the short url. If you open the shortened URL, "kurz" will do the expected thing an redirect you to the original URL. All functionality is shown below:

# store a URL $ curl -L http://localhost:9999/shorten/ --data-urlencode "url=https://github.com/fs111/kurz.go"

{"Key":"eIi","ShortUrl":"http://localhost:9999/eIi","LongUrl":"http://github.com/fs111/kurz.go","CreationDate":1321486517214982000,"Clicks":0}

# open a URL $ curl -L http://localhost:9999/eIi

Redirecting to: http://github.com/fs111/kurz.go

# show information about a url $ curl http://localhost:9999/eIi+ # notice the bit.ly style + in the end

{"Key":"eIi","ShortUrl":"http://localhost:9999/eIi","LongUrl":"http://github.com/fs111/kurz.go","CreationDate":1321486517214982000,"Clicks":1}

# list latest URLs $ curl http://localhost:9999/latest/1 { "urls" : [{"Key":"eIi","ShortUrl":"http://localhost:9999/eIi","LongUrl":"http://github.com/fs111/kurz.go","CreationDate":1321486517214982000,"Clicks":0}] }

All urls are stored in redis and if you set it up so, that it persists data to disk, the state can be kept forever. Since there is no real state within kurz.go, you could run multiple instances of it, but I have not tried it yet.

UI

The amazing @vormplus made a great looking frontend for kurz.go, which you can see, if you visit http://localhost:9999/index.htm. If you want to reload the latest urls on that page, just press "." and the table will be refreshed.

Testing it out

The 'stuff' directory contains a shell-script that imports a csv file into kurz.go. Just try it out!

Note: The csv file might contain some NSFW urls, I found it on the interwebs somewhere. You have been warned.

Have fun with it!

-- @fs111

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.