Involved Source Filesexceptions.gen.goexceptions.go
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)
Package-Level Type Names (total 5, all are exported)
/* sort exporteds by: | */
AcceptedLicenseInfo describes a license that is accepted by the discovery site.
NamestringURLstring
func AcceptedLicenses() []AcceptedLicenseInfo
A Detector detects licenses in a module and its packages.
allLicenses[]*License
// from directory to list of licenses
logffunc(string, ...interface{})
// licenses at module root directory, or list from exceptions
modulePathstringmoduleRedistboolversionstringzr*zip.Reader
AllLicenses returns all the licenses detected in the entire module, including
package licenses.
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.
computeAllLicenseInfo collects all the detected licenses in the zip and
stores them in the allLicenses field of d. It also maps detected licenses to
their directories, to optimize Detector.PackageInfo.
computeModuleInfo determines values for the moduleRedist and moduleLicenses fields of d.
detectFiles runs DetectFile on each of the given files.
If a file cannot be read, the error is logged and a license
of type unknown is added.
func NewDetector(modulePath, version string, zr *zip.Reader, logf func(string, ...interface{})) *Detector
func golang.org/x/pkgsite/internal/fetch.extractPackagesFromZip(ctx context.Context, modulePath, resolvedVersion string, r *zip.Reader, d *Detector, sourceInfo *source.Info) (_ []*fetch.goPackage, _ []*internal.PackageVersionState, err error)
func golang.org/x/pkgsite/internal/fetch.moduleUnits(modulePath, version string, pkgs []*fetch.goPackage, readmes []*internal.Readme, d *Detector) []*internal.Unit
A License is a classified license file path and its contents.
Contents[]byteMetadata*MetadataMetadata.Coveragelicensecheck.Coverage
FilePath is the '/'-separated path to the license file in the module zip,
relative to the contents directory.
The output of oldlicensecheck.Cover.
Types is the set of license types, as determined by the licensecheck package.
RemoveNonRedistributableData methods removes the license contents
if the license is non-redistributable.
func (*Detector).AllLicenses() []*License
func (*Detector).ModuleLicenses() []*License
func (*Detector).PackageInfo(dir string) (isRedistributable bool, lics []*License)
func golang.org/x/pkgsite/internal/testing/sample.Licenses() []*License
func (*Detector).detectFiles(files []*zip.File) []*License
func golang.org/x/pkgsite/internal/postgres.collectLicenses(rows *sql.Rows, bypassLicenseCheck bool) ([]*License, error)
func golang.org/x/pkgsite/internal/postgres.(*DB).getLicenses(ctx context.Context, fullPath, modulePath string, unitID int) (_ []*License, err error)
func golang.org/x/pkgsite/internal/postgres.(*DB).getModuleLicenses(ctx context.Context, moduleID int) (_ []*License, err error)
func golang.org/x/pkgsite/internal/testing/sample.AddLicense(m *internal.Module, lic *License)
func golang.org/x/pkgsite/internal/testing/sample.ReplaceLicense(m *internal.Module, lic *License)
func types(lics []*License) []string
func golang.org/x/pkgsite/internal/frontend.transformLicenses(modulePath, requestedVersion string, dbLicenses []*License) []frontend.License
func golang.org/x/pkgsite/internal/postgres.(*DB).compareLicenses(ctx context.Context, moduleID int, lics []*License) (err error)
func golang.org/x/pkgsite/internal/testing/sample.replaceLicense(lic *License, lics []*License)
func golang.org/x/pkgsite/internal/testing/sample.replaceLicense(lic *License, lics []*License)
var golang.org/x/pkgsite/internal/testing/sample.NonRedistributableLicense *License
Metadata holds information extracted from a license file.
Coveragelicensecheck.Coverage
FilePath is the '/'-separated path to the license file in the module zip,
relative to the contents directory.
The output of oldlicensecheck.Cover.
Types is the set of license types, as determined by the licensecheck package.
func golang.org/x/pkgsite/internal/testing/sample.LicenseMetadata() []*Metadata
func golang.org/x/pkgsite/internal/postgres.zipLicenseMetadata(licenseTypes []string, licensePaths []string) (_ []*Metadata, err error)
func golang.org/x/pkgsite/internal/frontend.transformLicenseMetadata(dbLicenses []*Metadata) []frontend.LicenseMetadata
func golang.org/x/pkgsite/internal/postgres.compareLicenses(i, j *Metadata) bool
Package-Level Functions (total 13, in which 4 are exported)
AcceptedLicenses returns a sorted slice of license types that are accepted as
redistributable. Its result is intended to be displayed to users.
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.
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.
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.
isVendoredFile reports if the given file is in a proper subdirectory nested
under a 'vendor' directory, to allow for Go packages named 'vendor'.
e.g. isVendoredFile("vendor/LICENSE") == false, and
isVendoredFile("vendor/foo/LICENSE") == true
pathPrefix appends a "/" to its argument if the argument is non-empty.
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.
fileNamesLowercase has all the entries of FileNames, downcased and made a set
for fast case-insensitive matching.
These aren't technically licenses, but they are recognized by
licensecheck and safe to ignore.
Files we should ignore.
Set of "modulePath filePath".
maxLicenseSize is the maximum allowable size (in bytes) for a license file.
There are some license files larger than 1 million bytes: https://github.com/vmware/vic/LICENSE
and github.com/goharbor/harbor/LICENSE, for example.
var for testing
nonOSILicenses lists licenses that are not approved by OSI.
redistributableLicenseTypes is the set of license types, as reported by
licensecheck, that allow redistribution. It consists of the standard
types along with some exception types.
standardRedistributableLicenseTypes is the list of license types, as reported by
licensecheck, that allow redistribution, and also have a name that is an OSI or SPDX
identifier.
Package-Level Constants (total 73, in which 3 are exported)
All files; the union of root and non-root.
Only files that are not in the root directory.
Only files from the root (contents) directory.
coverageThreshold is the minimum percentage of the file that must contain
license text.
constlicense_AGPL_3_0_lre = "\n\n\n\n\n\n//**\nGNU Affero General Public License v3.0\nhttps://ww...
constlicense_yottadb_lre = "//** lang.yottadb.com/go/yottadb@v1.1.0 **//\n\n\n\nAll software in ...
unknownLicenseType is for text in a license file that's not recognized.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.