licensor

package module
v0.0.0-...-8950282 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 4 Imported by: 0

README

License GoDoc Go Report Card CircleCI

Licensor

📝 Detect what license a project is distributed under

Installing

You can fetch this library by running the following

go get -u github.com/joshdk/licensor

Usage

import (
	"fmt"
	"github.com/joshdk/licensor"
)

// Example content from https://github.com/golang/go/blob/master/LICENSE
const unknown = `
	Copyright (c) 2009 The Go Authors. All rights reserved.
	Redistribution and use in source and binary forms, with or without
	...
	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
	OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`

// Find license that is the closest match 
match := licensor.Best([]byte(unknown))

fmt.Printf("License name:     %s\n",   match.License.Name)
fmt.Printf("SPDX identifier:  %s\n",   match.License.Identifier)
fmt.Printf("Match confidence: %.2f\n", match.Confidence)
// License name:     BSD 3-clause "New" or "Revised" License
// SPDX identifier:  BSD-3-Clause
// Match confidence: 0.96

License

This library is distributed under the MIT License, see LICENSE.txt for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match struct {

	// Confidence is the statistical certainty of the match. Value lies within
	// the interval [0, 1] to where 0 is less confident and 1 is more
	// confident.
	Confidence float64

	// License is the matched SPDX license.
	License spdx.License
}

A Match represents the result of a statistical comparison against a specific license.

func Best

func Best(unknown []byte) Match

Best returns the license that is the closest match to the given text.

func Closest

func Closest(unknown []byte, threshold float64) Match

Closest returns the first license with a match confidence that exceeds threshold, or the closest match to the given text if none meet the threshold.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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