Documentation
¶
Overview ¶
Spdxexp package validates licenses and determines if a license expression is satisfied by a list of licenses. Validity of a license is determined by the SPDX license list.
Index ¶
Examples ¶
- Satisfies (And)
- Satisfies (AndNotFound)
- Satisfies (ErrorUnknownLicense)
- Satisfies (ExtraAllowedLicense)
- Satisfies (Only)
- Satisfies (OnlyNotFound)
- Satisfies (Or)
- Satisfies (OrLater)
- Satisfies (OrLaterNotFound)
- Satisfies (OrNotFound)
- Satisfies (Plus)
- Satisfies (PlusNotFound)
- Satisfies (SingleLicense)
- ValidateLicenses (AllBad)
- ValidateLicenses (AllGood)
- ValidateLicenses (OneBad)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractLicenses ¶ added in v2.2.0
ExtractLicenses extracts licenses from the given expression without duplicates. Returns an array of licenses or error if error occurs during processing.
func Satisfies ¶
Satisfies determines if the allowed list of licenses satisfies the test license expression. Returns true if allowed list satisfies test license expression; otherwise, false. Returns error if error occurs during processing.
Example (And) ¶
fmt.Println(Satisfies("Apache-2.0 AND MIT", []string{"MIT", "Apache-2.0"}))
Output: true <nil>
Example (AndNotFound) ¶
fmt.Println(Satisfies("MIT AND Apache-2.0", []string{"MIT"}))
Output: false <nil>
Example (ErrorUnknownLicense) ¶
fmt.Println(Satisfies("GPL", []string{"GPL"}))
Output: false unknown license 'GPL' at offset 0
Example (ExtraAllowedLicense) ¶
fmt.Println(Satisfies("MIT AND Apache-2.0", []string{"MIT", "Apache-1.0", "Apache-2.0"}))
Output: true <nil>
Example (Only) ¶
fmt.Println(Satisfies("Apache-1.0", []string{"Apache-1.0-only"}))
Output: true <nil>
Example (OnlyNotFound) ¶
fmt.Println(Satisfies("Apache-2.0", []string{"Apache-1.0-only"}))
Output: false <nil>
Example (Or) ¶
fmt.Println(Satisfies("MIT OR Apache-2.0", []string{"MIT"}))
Output: true <nil>
Example (OrLater) ¶
fmt.Println(Satisfies("Apache-2.0", []string{"Apache-1.0-or-later"}))
Output: true <nil>
Example (OrLaterNotFound) ¶
fmt.Println(Satisfies("Apache-1.0", []string{"Apache-2.0-or-later"}))
Output: false <nil>
Example (OrNotFound) ¶
fmt.Println(Satisfies("MIT OR Apache-2.0", []string{"GPL-2.0"}))
Output: false <nil>
Example (Plus) ¶
fmt.Println(Satisfies("Apache-2.0", []string{"Apache-1.0+"}))
Output: true <nil>
Example (PlusNotFound) ¶
fmt.Println(Satisfies("Apache-1.0", []string{"Apache-2.0+"}))
Output: false <nil>
Example (SingleLicense) ¶
fmt.Println(Satisfies("MIT", []string{"MIT"}))
Output: true <nil>
func ValidateLicenses ¶
ValidateLicenses checks if given licenses are valid according to spdx. Returns true if all licenses are valid; otherwise, false. Returns all the invalid licenses contained in the `licenses` argument.
Example (AllBad) ¶
fmt.Println(ValidateLicenses([]string{"MTI", "Apache--2.0", "GPL"}))
Output: false [MTI Apache--2.0 GPL]
Example (AllGood) ¶
fmt.Println(ValidateLicenses([]string{"MIT", "Apache-2.0", "GPL-2.0"}))
Output: true []
Example (OneBad) ¶
fmt.Println(ValidateLicenses([]string{"MIT", "Apache-2.0", "GPL"}))
Output: false [GPL]
Types ¶
This section is empty.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Spdxlicenses package provides functions to get licenses, deprecated licenses, and exceptions.
|
Spdxlicenses package provides functions to get licenses, deprecated licenses, and exceptions. |