import "golang.org/x/pkgsite/internal/licenses"
Package licenses detects licenses and determines whether they are redistributable. The functions in this package do not return errors; instead, they log any problems they encounter and fail closed by reporting that the module or package is not redistributable.
Example (modproxy):
d := licenses.NewDetector(modulePath, version, zipReader, log.Infof) modRedist := d.ModuleIsRedistributable()
Example (discovery):
d := licenses.NewDetector(modulePath, version, zipReader, log.Infof) modRedist := d.ModuleIsRedistributable() lics := d.AllLicenses() pkgRedist, pkgMetas := d.PackageInfo(pkgSubdir)
exceptions.gen.go exceptions.go licenses.go
var ( FileNames = []string{ "COPYING", "COPYING.md", "COPYING.markdown", "COPYING.txt", "LICENCE", "LICENCE.md", "LICENCE.markdown", "LICENCE.txt", "LICENSE", "LICENSE.md", "LICENSE.markdown", "LICENSE.txt", "LICENSE-2.0.txt", "LICENCE-2.0.txt", "LICENSE-APACHE", "LICENCE-APACHE", "LICENSE-APACHE-2.0.txt", "LICENCE-APACHE-2.0.txt", "LICENSE-MIT", "LICENCE-MIT", "LICENSE.MIT", "LICENCE.MIT", "LICENSE.code", "LICENCE.code", "LICENSE.docs", "LICENCE.docs", "LICENSE.rst", "LICENCE.rst", "MIT-LICENSE", "MIT-LICENCE", "MIT-LICENSE.md", "MIT-LICENCE.md", "MIT-LICENSE.markdown", "MIT-LICENCE.markdown", "MIT-LICENSE.txt", "MIT-LICENCE.txt", "MIT_LICENSE", "MIT_LICENCE", "UNLICENSE", "UNLICENCE", } )
func DetectFile(contents []byte, filename string, logf func(string, ...interface{})) ([]string, licensecheck.Coverage)
DetectFile return the set of license types for the given file contents. It also returns the licensecheck coverage information. The filename is used solely for logging.
Redistributable reports whether the set of license types establishes that a module or package is redistributable. All the licenses we see that are relevant must be redistributable, and we must see at least one such license.
AcceptedLicenseInfo describes a license that is accepted by the discovery site.
func AcceptedLicenses() []AcceptedLicenseInfo
AcceptedLicenses returns a sorted slice of license types that are accepted as redistributable. Its result is intended to be displayed to users.
type Detector struct {
// contains filtered or unexported fields
}
A Detector detects licenses in a module and its packages.
func NewDetector(modulePath, version string, zr *zip.Reader, logf func(string, ...interface{})) *Detector
NewDetector returns a Detector for the given module and version. zr should be the zip file for that module and version. logf is for logging; if nil, no logging is done.
AllLicenses returns all the licenses detected in the entire module, including package licenses.
func (d *Detector) Files(which WhichFiles) []*zip.File
Files returns a list of license files from the zip. The which argument determines the location of the files considered.
ModuleIsRedistributable reports whether the given module is redistributable.
ModuleLicenses returns the licenses that apply to the module.
PackageInfo reports whether the package at dir, a directory relative to the module root, is redistributable. It also returns all the licenses that apply to the package.
A License is a classified license file path and its contents.
RemoveNonRedistributableData methods removes the license contents if the license is non-redistributable.
type Metadata struct { // Types is the set of license types, as determined by the licensecheck package. Types []string // FilePath is the '/'-separated path to the license file in the module zip, // relative to the contents directory. FilePath string // The output of oldlicensecheck.Cover. OldCoverage oldlicensecheck.Coverage Coverage licensecheck.Coverage }
Metadata holds information extracted from a license file.
WhichFiles describes which files from the zip should be returned by Detector.Files.
const ( // Only files from the root (contents) directory. RootFiles WhichFiles = iota // Only files that are not in the root directory. NonRootFiles // All files; the union of root and non-root. AllFiles )
Package licenses imports 14 packages (graph) and is imported by 9 packages. Updated 2021-01-16. Refresh now. Tools for package owners.