pwnedpass

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 10 Imported by: 0

README

PwnedPass

Godoc

PwnedPass is a Go library for accessing the Pwned Password API. It currently only supports the V2 version of the API. It's got a dead simple API, tests, and benchmarks.

Usage

See godoc for usage and documentation.

Performance

Running on my computer, the benchmark results I get are:

BenchmarkCount-8                    5000            231893 ns/op
BenchmarkCountIntegration-8          100          24331000 ns/op

The test with a mock local HTTP server takes about 231893 ns/op, while the integration tests against the actual API take 24331000 ns/op, meaning the only real limitation is the speed of the API and your network.

Documentation

Overview

Package pwnedpass provides a library for accessing the Pwned Password API.

Usage:

count, err := pwnedpass.DefaultClient.Count("password")
if err != nil {
	panic(err)
}

fmt.Println(count)

You can also create your own Client for use with a different API or to use a different HTTP client:

 client := pwnedpass.ClientV2{
	 HTTPClient: &http.Client{
		 Timeout: time.Second * 2,
	 },
 }

 count, err := client.Count("password")
 if err != nil {
	 panic(err)
 }

 fmt.Println(count)

Index

Constants

View Source
const BaseURLV2 = "https://api.pwnedpasswords.com"

BaseURLV2 is the base URL for the V2 Pwned Passwords API.

Variables

View Source
var DefaultClient = &ClientV2{
	HTTPClient: &http.Client{
		Timeout: time.Second * 5,
	},
}

DefaultClient is the default client used for making requests to the PwnedPass API. It uses the V2 client with the https://api.pwnedpasswords.com base URL. It has a sane timeout of 5 seconds.

Functions

This section is empty.

Types

type ClientV2

type ClientV2 struct {
	HTTPClient *http.Client
	BaseURL    string
}

ClientV2 is used for making requests to the PwnedPass V2 API.

func (*ClientV2) Count

func (c *ClientV2) Count(ctx context.Context, password string) (int, error)

Count returns the numbers of passwords associated with a given password. Count will use http.DefaultClient if the Client HTTPClient is nil and it will use BaseURLV2 if the Client BaseURL is empty. This means ClientV2 has a usable zero value.

Jump to

Keyboard shortcuts

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