urlexpander

command module
v0.0.0-...-61a7ea1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 10 Imported by: 0

README

UrlExpander

GoDoc

Go package providing API for expanding shortened urls from services like goo.gl, bitly.com, tinyurl.com

Features

  • Translates shortened urls as fast as possible by sending lightweight HEAD request to shortening service
  • Uses local cache to handle repeated queries
  • Respects robots.txt in case the shortening service must not be visited by crawlers

Usage

This project can be used either as a library from Go code or it can be used as a standalone service providing HTTP API.

Library
import "github.com/vanekjar/urlexpander/lib"

expander := urlexpander.New()
expanded, err := expander.ExpandUrl("https://goo.gl/HFoP0a")
HTTP API server

Install UrlExpander locally

go get github.com/vanekjar/urlexpander

Run command that will start a local HTTP server (listening on port 8080 by default)

urlexpander

Check running server by visiting http://localhost:8080

API description
Request
GET http://urlexpander.tk/api/expand?url=https://goo.gl/HFoP0a
Response
200 OK
{"original":"https://goo.gl/HFoP0a", "expanded":"http://urlexpander.tk"} 

Configuration

conf := urlexpander.Config{
  // Expanded urls are cached for repeated queries. Set cache capacity.
  CacheCapacity:     cacheCapacity,
  // Set cache expiration time in minutes.
  CacheExpiration:   cacheExpiration,
  // User agent string used when translating shortened url.
  UserAgent:         userAgent,
  // Maximum length of shortened url. It is assumed that no shortened url is longer than that.
  ShortUrlMaxLength: 32,
}

expander := urlexpander.NewFromConfig(conf)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package urlexpander provides a library to expand shortened urls from services like goo.gl, bitly.com, tinyurl.com
Package urlexpander provides a library to expand shortened urls from services like goo.gl, bitly.com, tinyurl.com

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL