Documentation ¶
Index ¶
Constants ¶
const ( // Recognized license types LicenseMIT = "MIT" LicenseNewBSD = "NewBSD" LicenseFreeBSD = "FreeBSD" LicenseApache20 = "Apache-2.0" LicenseMPL20 = "MPL-2.0" LicenseGPL20 = "GPL-2.0" LicenseGPL30 = "GPL-3.0" LicenseLGPL21 = "LGPL-2.1" LicenseLGPL30 = "LGPL-3.0" LicenseCDDL10 = "CDDL-1.0" LicenseEPL10 = "EPL-1.0" // Various errors ErrNoLicenseFile = "license: unable to find any license file" ErrUnrecognizedLicense = "license: could not guess license type" )
Variables ¶
var DefaultLicenseFiles = []string{
"LICENSE", "LICENSE.txt", "LICENSE.md", "license.txt",
"COPYING", "COPYING.txt", "COPYING.md", "copying.txt",
}
A set of reasonable license file names to use when guessing where the license may be.
var KnownLicenses = []string{ LicenseMIT, LicenseNewBSD, LicenseFreeBSD, LicenseApache20, LicenseMPL20, LicenseGPL20, LicenseGPL30, LicenseLGPL21, LicenseLGPL30, LicenseCDDL10, LicenseEPL10, }
A slice of standardized license abbreviations
Functions ¶
This section is empty.
Types ¶
type License ¶
type License struct { Type string // The type of license in use Text string // License text data File string // The path to the source file, if any }
License describes a software license
func NewFromDir ¶
NewFromDir will search a directory for well-known and accepted license file names, and if one is found, read in its content and guess the license type.
func NewFromFile ¶
NewFromFile will attempt to load a license from a file on disk, and guess the type of license based on the bytes read.
func (*License) GuessFile ¶
GuessFile searches a given directory (non-recursively) for files with well- established names that indicate license content.
func (*License) GuessType ¶
GuessType will scan license text and attempt to guess what license type it describes. It will return the license type on success, or an error if it cannot accurately guess the license type.
This method is a hack. It might be more accurate to also scan the entire body of license text and compare it using an algorithm like Jaro-Winkler or Levenshtein against a generic version. The problem is that some of the common licenses, such as GPL-family licenses, are quite large, and running these algorithms against them is considerably more expensive and is still not completely deterministic on which license is in play. For now, we will just scan until we find differentiating strings and call that good-enuf.gov.
func (*License) Recognized ¶
Recognized determines if the license is known to go-license.