Documentation ¶
Overview ¶
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)
Index ¶
Constants ¶
This section is empty.
Variables ¶
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",
}
)
var ( // OmitExceptions causes the list of exceptions to be omitted from license detection. // It is intended only to speed up testing, and must be set before the first use // of this package. OmitExceptions bool )
Functions ¶
func DetectFile ¶
func DetectFile(contents []byte, filename string, logf func(string, ...any)) ([]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.
func Redistributable ¶
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.
Types ¶
type AcceptedLicenseInfo ¶
AcceptedLicenseInfo describes a license that is accepted by the discovery site.
func AcceptedLicenses ¶
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 ¶
type Detector struct {
// contains filtered or unexported fields
}
A Detector detects licenses in a module and its packages.
func NewDetector ¶
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. Deprecated: use NewDetectorFS.
func NewDetectorFS ¶
NewDetectorFS returns a Detector for the given module and version. fsys should represent the content directory of the module (not the zip root). logf is for logging; if nil, no logging is done.
func (*Detector) AllLicenses ¶
AllLicenses returns all the licenses detected in the entire module, including package licenses.
func (*Detector) ModuleIsRedistributable ¶
ModuleIsRedistributable reports whether the given module is redistributable.
func (*Detector) ModuleLicenses ¶
ModuleLicenses returns the licenses that apply to the module.
type License ¶
A License is a classified license file path and its contents.
func (*License) RemoveNonRedistributableData ¶
func (l *License) RemoveNonRedistributableData()
RemoveNonRedistributableData methods removes the license contents if the license is non-redistributable.
type Metadata ¶
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 Coverage licensecheck.Coverage }
Metadata holds information extracted from a license file.
type WhichFiles ¶
type WhichFiles int
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 )