licenses

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package licenses provides some structures for handling and representing software licenses. It uses SPDX representations for part of it, because there doesn't seem to be a better alternative. It doesn't guarantee that it implements all of the SPDX spec. If there's an aspect which you think was mis-implemented or is missing, please let us know. XXX: Add a test to check if the license-list-data submodule is up-to-date!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InList added in v0.0.2

func InList(needle *License, haystack []*License) bool

InList returns true if a license exists inside a list, otherwise false. It uses the license Cmp method to determine equality.

func Join

func Join(licenses []*License) string

Join joins the string representations of a list of licenses with comma space.

Types

type License

type License struct {
	// SPDX is the well-known SPDX ID for the license.
	SPDX string

	// Origin shows a different license provenance, and associated custom
	// name. It should probably be a "reverse-dns" style unique identifier.
	Origin string
	// Custom is a custom string that is a unique identifier for the license
	// in the aforementioned Origin namespace.
	Custom string
}

License is a representation of a license. It's better than a simple SPDX ID as a string, because it allows us to store alternative representations to an internal or different representation, as well as any other information that we want to have associated here.

func StringToLicense added in v0.0.2

func StringToLicense(name string) (*License, error)

StringToLicense takes an input string and returns a license struct. This can handle both normal SPDX ID's and the origin strings in the `name(origin)` format. It rarely returns an error unless you pass it an obviously fake license identifier. TODO: add some tests

func StringsToLicenses added in v0.0.2

func StringsToLicenses(inputs []string) ([]*License, error)

StringsToLicenses converts a list of input strings and converts them into the matching list of license structs. It accepts non-SPDX license names in the standard SPDX format of `name(origin)`.

func Union added in v0.0.2

func Union(haystack1 []*License, haystack2 []*License) []*License

Union returns the union of licenses in both input lists. It uses the pointers from the first list in the results. It does not try to remove duplicates so if either list has duplicates, you may end up with duplicates in the result. It uses the license Cmp method to determine equality.

func (*License) Cmp

func (obj *License) Cmp(license *License) error

Cmp compares two licenses and determines if they are identical.

func (*License) String

func (obj *License) String() string

String returns a string representation of whatever license is specified.

func (*License) Validate

func (obj *License) Validate() error

Validate returns an error if the license doesn't have a valid representation. For example, if you express the license as an SPDX ID, this will validate that it is among the known licenses.

type LicenseListSPDX

type LicenseListSPDX struct {
	Version string `json:"licenseListVersion"`

	Licenses []*LicenseSPDX `json:"licenses"`
}

LicenseListSPDX is modelled after the official SPDX licenses.json file.

var (
	LicenseList LicenseListSPDX // this gets populated during init()
)

type LicenseSPDX

type LicenseSPDX struct {
	// Reference is a link to the full license .json file.
	Reference    string `json:"reference"`
	IsDeprecated bool   `json:"isDeprecatedLicenseId"`
	DetailsURL   string `json:"detailsUrl"`
	// ReferenceNumber is an index number for the license. I wouldn't
	// consider this to be stable over time.
	ReferenceNumber int64 `json:"referenceNumber"`
	// Name is a friendly name for the license.
	Name string `json:"name"`
	// LicenseID is the SPDX ID for the license.
	LicenseID     string   `json:"licenseId"`
	SeeAlso       []string `json:"seeAlso"`
	IsOSIApproved bool     `json:"isOsiApproved"`

	//IsDeprecated bool `json:"isDeprecatedLicenseId"` // appears again
	IsFSFLibre bool   `json:"isFsfLibre"`
	Text       string `json:"licenseText"`
}

LicenseSPDX is modelled after the official SPDX license entries. It also includes fields from the referenced fields, which include the full text.

func ID

func ID(spdx string) (*LicenseSPDX, error)

ID looks up the license from the imported list. Do not modify the result as it is the global database that everyone is using.

Jump to

Keyboard shortcuts

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