GoPuny
A package and CLI tool to use SAPO's URL shortening service.
Install
$ go get github.com/olshevskiy87/gopuny
Usage
- CLI tool
gopuny
$ gopuny -h
Usage: gopuny ACTION URL
Positional arguments:
ACTION "short" or "expand"
URL url to short or expand
Options:
--help, -h display this help and exit
$ gopuny short https://www.google.com
Unicode http://㐃鍍.sl.pt
ASCII http://37.sp.sl.pt
Preview http://37.sp.sl.pt/-
Original https://www.google.com
$ gopuny expand http://37.sp.sl.pt
https://www.google.com/
- Using package
punyurl
package main
import (
"fmt"
"os"
"github.com/olshevskiy87/gopuny/punyurl"
)
func main() {
puny, err := punyurl.New("https://www.google.com")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
result, err := puny.Short()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("%#v\n", result)
// output:
// &result.Result{ASCII:"http://37.sp.sl.pt", Preview:"http://37.sp.sl.pt/-", Puny:"http://㐃鍍.sl.pt", URL:"https://www.google.com"}
}
Motivations
Inspired by perl-module WWW::Shorten::PunyURL
License
MIT. See LICENSE for details.