pkgsite: golang.org/x/pkgsite/internal/licenses Index | Files

package licenses

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)

Index

Package Files

exceptions.gen.go exceptions.go licenses.go

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",
    }
)

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.

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 {
    *Metadata
    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 licensecheck.Cover.
    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.
    NonRootFiles
    // All files; the union of root and non-root.
    AllFiles
)

Package licenses imports 13 packages (graph) and is imported by 10 packages. Updated 2020-10-28. Refresh now. Tools for package owners.