https://github.com/vanekjar/urlexpander
Go package providing API for expanding shortened urls from services like goo.gl, bitly.com, tinyurl.com
https://github.com/vanekjar/urlexpander
api expanding-shortened-urls go golang shortener tinyurl
Last synced: 9 months ago
JSON representation
Go package providing API for expanding shortened urls from services like goo.gl, bitly.com, tinyurl.com
- Host: GitHub
- URL: https://github.com/vanekjar/urlexpander
- Owner: vanekjar
- License: mit
- Created: 2017-01-15T19:53:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-10-14T00:41:43.000Z (over 4 years ago)
- Last Synced: 2025-01-03T23:43:31.864Z (over 1 year ago)
- Topics: api, expanding-shortened-urls, go, golang, shortener, tinyurl
- Language: Go
- Homepage:
- Size: 871 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UrlExpander
[](https://godoc.org/github.com/vanekjar/urlexpander/lib)
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
```go
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)
```bash
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
```go
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)
```