unfurl

package module
v0.0.0-...-7d2760b Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2017 License: MIT Imports: 4 Imported by: 0

README

go-unfurl

Build Status Go Report Card codecov GoDoc

go-unfurl is a simple library that follow all redirects of a given URL.

package main

import (
  "fmt"

  "github.com/victorgama/go-unfurl"
)

func main() {
  client := unfurl.NewClient()
  res, err := client.Process("http://goo.gl/g0DEfq")
  if err != nil {
    panic(err)
  }
  fmt.Println(res)
}

// => https://github.com

Installing

  1. Download and install it:
$ go get -u github.com/victorgama/go-unfurl
  1. Import it in your code:
import "github.com/victorgama/go-unfurl"

Usage

By default, this library will follow 20 redirects and return an ErrTooManyRedirects when this value is surpassed.

client := unfurl.NewClient() // 20 max redirects
// ...or you can define a custom value
client := unfurl.NewClientWithOptions(unfurl.Options{MaxHops: 27})

License

MIT License

Copyright (c) 2016 Victor Gama

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTooManyRedirects = errors.New("Too many redirects")

ErrTooManyRedirects indicates that the unfurl client has archieved the maximum allowed request count defined by the Options struct

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a unfurl client instance

func NewClient

func NewClient() Client

NewClient returns a new instance of a Client using the default values for the settings parameters. (MaxHops: 20) (UserAgent: nil)

func NewClientWithOptions

func NewClientWithOptions(opts Options) Client

NewClientWithOptions returns a new instance of a Client using the provided Options values

func (*Client) Process

func (c *Client) Process(in string) (string, error)

Process attempts to follow all possible redirects of a given URL

type Options

type Options struct {
	// MaxHops defines how many redirects the client can suffer before returning
	// an error
	MaxHops int
	// UserAgent defines the UserAgent value used by the underlying http client
	UserAgent *string
}

Options exposes internal settings to change the Client behaviour

Jump to

Keyboard shortcuts

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