pkgsite: Index | Files

package licenses

import ""

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 Files

exceptions.gen.go exceptions.go licenses.go


var (
    FileNames = []string{

func DetectFile Uses

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.

func Redistributable Uses

func Redistributable(licenseTypes []string) bool

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.

type AcceptedLicenseInfo Uses

type AcceptedLicenseInfo struct {
    Name string
    URL  string

AcceptedLicenseInfo describes a license that is accepted by the discovery site.

func AcceptedLicenses Uses

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 Uses

type Detector struct {
    // contains filtered or unexported fields

A Detector detects licenses in a module and its packages.

func NewDetector Uses

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.

func (*Detector) AllLicenses Uses

func (d *Detector) AllLicenses() []*License

AllLicenses returns all the licenses detected in the entire module, including package licenses.

func (*Detector) Files Uses

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.

func (*Detector) ModuleIsRedistributable Uses

func (d *Detector) ModuleIsRedistributable() bool

ModuleIsRedistributable reports whether the given module is redistributable.

func (*Detector) ModuleLicenses Uses

func (d *Detector) ModuleLicenses() []*License

ModuleLicenses returns the licenses that apply to the module.

func (*Detector) PackageInfo Uses

func (d *Detector) PackageInfo(dir string) (isRedistributable bool, lics []*License)

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.

type License Uses

type License struct {
    Contents []byte

A License is a classified license file path and its contents.

func (*License) RemoveNonRedistributableData Uses

func (l *License) RemoveNonRedistributableData()

RemoveNonRedistributableData methods removes the license contents if the license is non-redistributable.

type Metadata Uses

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.

type WhichFiles Uses

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.
    // All files; the union of root and non-root.

Package licenses imports 14 packages (graph) and is imported by 9 packages. Updated 2021-01-16. Refresh now. Tools for package owners.