Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 2.12 KB

README.md

File metadata and controls

110 lines (80 loc) · 2.12 KB

shorten - an url shortening library

Shorten helps you easily convert long urls to short ones with multiple service providers.

Install

go get -u github.com/aleyrizvi/shorten-go

Example usage

package main

import (
	"fmt"
	"os"

	bitly "github.com/aleyrizvi/bit.ly"
	"github.com/aleyrizvi/shorten-go"
)

func main() {
	btly := bitly.New("MY_BITLY_KEY")
	sh := shorten.New()

	sh.AddProvider("bitly", btly)

	url, err := sh.Shorten(&shorten.UrlParams{
		Destination: "github.com/aleyrizvi/shorten-go",
	})

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(-1)
	}

	fmt.Println(url)
}

Usage with multiple providers

package main

import (
	"fmt"
	"os"

	bitly "github.com/go-shorten/bit.ly"
	"github.com/go-shorten/shorten"
	...
)

func main() {
	btly := bitly.New("MY_BITLY_KEY")
	rebrandly := rebrandly.New(...)
	sh := shorten.New()

	sh.AddProvider("bitly", btly)
	sh.AddProvider("rebrandly", btly)

	url, err := sh.With("rebrandly").Shorten(&shorten.UrlParams{
		Destination: "https://github.com/go-shorten/shorten",
	})

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(-1)
	}

	fmt.Println(url)
}

Features

  • Good test coverage
  • Multiple providers
  • Custom URL shortener with redis (coming soon)

Providers

Currently we are supporting bit.ly at the moment but other providers will be available really soon.

Following is the list of providers in pipeline. Feel free to create a pull request if you like to contribute or reach out if your required provider is not in list.


Contributions

We would love to accept contributions on this project. You can help us by:

  • Writing godocs
  • Write github actions to run go tests. I may be writing it pretty soon anyway.
  • Add other providers.
  • Refactor code and send pull requests.
  • Improve tutorial on this readme.

Maintainers