googl.go is an open source implementation of Google URL Shortener API service writen in go.
googl.go is licensed under the BSD-style lincense, which can be found in the LICENSE file.
- make sure you have a working go environment ( See the Install Instructions ).
git clone git://github.com/mcspring/googl.go.git
cd googl.go
&&make install
import (
"os"
"fmt"
"googl"
)
const (
API_GOOGL_KEY = "" // your google url shorten api key, default is empty
)
func main() {
longUrl := "http://www.google.com"
urlapi := googl.NewGoogl(GOOGL_KEY)
shortUrl, err := urlapi.Shorten(longUrl)
if nil != err {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Short URL: %s\n", shortUrl)
longUrl, err = urlapi.Expand(shortUrl)
if nil != err {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Long URL: %s\n", longUrl)
}
This will output:
Short URL: http://goo.gl/fbsS
Long URL: http://www.google.com/
if success, or other error message.
googl.go only implement url.insert and url.get of Google URL Shortener APIs now.
googl.go is written by Spring Mc.
And you can follow me on Twitter!