Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
/ go-bitly Public archive

a simple bit.ly client for go to easily shorten urls

License

Notifications You must be signed in to change notification settings

streamrail/go-bitly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

go-bitly Circle CI

a simple bit.ly client for go to easily shorten urls.

usage

get the package:

    $ go get github.com/streamrail/go-bitly

import it, set your auth token, and let the party begin:

package main

import (
	"flag"
	"github.com/streamrail/go-bitly"
)

var (
	token = flag.String("apiKey", "", "your bit.ly api key")
)

func TestBitly(t *testing.T) {
	flag.Parse()

	if *token == "" {
		t.Error("required flag: token")
	}

	bitlyClient := bitly.NewClient(*token)

	var testUrl = "https://github.com/streamrail/go-bitly"

	if shortUrl, err := bitlyClient.Shorten(testUrl); err != nil {
		t.Error(err.Error())
	} else {
		// do awesome stuff with shortUtl
	}
}

run tests

In order to run the tests, you must set your auth token. The tests work by requesting bit.ly to shorten "https://github.com/streamrail/go-bitly". Then we try to http GET the shortURl, and we follow the redirect chain for 10 seconds. During those 10 seconds, if we got the original URL, we send it on a channel and the test passes.

License

MIT (see LICENSE file)

About

a simple bit.ly client for go to easily shorten urls

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages