hasher

package
v0.0.0-...-2fccd27 Latest Latest
Warning

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

Go to latest
Published: May 12, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package hasher includes functions and structures to ease the process of hashing the contents present in an URL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Get(url string) (resp *http.Response, err error)
}

Client is an interface that represents an HTTP client.

type HTTPClient

type HTTPClient struct{}

HTTPClient represents an implementation of an HTTPClient that uses the "net/http" package.

func (*HTTPClient) Get

func (client *HTTPClient) Get(url string) (resp *http.Response, err error)

Get makes an HTTP GET request using the "net/http" package.

type HTTPHasher

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

HTTPHasher is an implementation of the interface Hasher, by doing an HTTP GET to the URL supplied and hashing the results with MD5.

func NewHTTPHasher

func NewHTTPHasher(client Client) *HTTPHasher

NewHTTPHasher returns a new http-based hasher, using the client supplied.

func (*HTTPHasher) Hash

func (hasher *HTTPHasher) Hash(url string) (string, error)

Hash makes a http GET to the url defined in the parameter and returns the MD5 hashed value of the response, or an error if that was not possible.

type Hasher

type Hasher interface {
	// Hash retrieves the md5 hash (as a string) of the contents of the url.
	Hash(url string) (string, error)
}

Hasher is an interface that represents the capability of hashing the contents present in a URL.

type MockHasher

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

MockHasher is an implementation of the interface Hasher, that has an internal map of urls to hashes.

func NewMockHasher

func NewMockHasher(hashMap map[string]string) *MockHasher

NewMockHasher returns a MockHasher with a certain map of urls to hashes.

func (*MockHasher) Hash

func (hasher *MockHasher) Hash(url string) (string, error)

Hash returns the corresponding hash to the url parameter, or an error if that is not possible.

Jump to

Keyboard shortcuts

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