urlexpander

package
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: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var ErrDisallowedByRobotsTxt = errors.New("Provided URL is disallowed by robots.txt")
View Source
var ErrInvalidUrl = errors.New("Provided URL is not valid")
View Source
var ErrLongUrl = errors.New("Provided URL is not shortened")

Functions

This section is empty.

Types

type Config

type Config struct {
	// User agent string used when translating shortened url.
	UserAgent string

	// Maximum length of shortened url. It is assumed that no shortened url is longer than that.
	ShortUrlMaxLength int

	// Expanded urls are cached for repeated use. Using this option cache capacity can be set.
	CacheCapacity int

	// Expanded urls are cached for repeated use. Using this option expiration timeout can be set.
	CacheExpiration time.Duration
}

type UrlExpander

type UrlExpander interface {
	// Expand given shortened url to its original form.
	// Return either an expanded url as a string or an error.
	ExpandUrl(shortenedUrl string) (string, error)
}

func New

func New() UrlExpander

Create a new UrlExpander with default config

func NewFromConfig

func NewFromConfig(config Config) UrlExpander

Create a new UrlExpander with provided config

Jump to

Keyboard shortcuts

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