spdxexp

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 5 Imported by: 44 modules, 41 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Satisfies

func Satisfies(testExpression string, allowedList []string) (bool, error)

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

func ValidateLicenses(licenses []string) (bool, []string)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL