Skip to content

mcspring/googl.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

googl.go

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.

Installation

  1. make sure you have a working go environment ( See the Install Instructions ).
  2. git clone git://github.com/mcspring/googl.go.git
  3. cd googl.go && make install

Example

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.

Attention

googl.go only implement url.insert and url.get of Google URL Shortener APIs now.

About

googl.go is written by Spring Mc.

And you can follow me on Twitter!

About

The goo.gl URL shortener API implemented in go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published