spdx

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: MIT Imports: 5 Imported by: 13

README

go-spdx Godoc

go-spdx is a Go library for listing and looking up licenses using SPDX IDs. SPDX IDs are an unambiguous way to reference a specific software license. The IDs are looked up using the spdx.org website (or custom URLs may be specified). Offline lookup is not currently supported.

This library does not implement the SPDX document format. SPDX document parsing and printing are provided by other libraries, including a library in the official spdx organization. This library instead provides the ability to look up licenses via SPDX IDs.

Usage

// Get the list of all known licenses
list, err := spdx.List()

// Get a single license with more detail such as the license text
lic, err := spdx.License("MIT")

// Create a custom client so you can control the HTTP client or the URLs
// that are used to access licenses.
client := &spdx.Client{ /* ... */ }
client.List()
client.License("MIT")

Documentation

Index

Constants

View Source
const (
	DefaultListURL    = "https://spdx.org/licenses/licenses.json"
	DefaultDetailsURL = "https://spdx.org/licenses/%[1]s.json"
)

Variables

View Source
var DefaultClient = &Client{}

DefaultClient is the default Client used by the top-level functions List, License, etc.

Functions

This section is empty.

Types

type Client

type Client struct {
	// HTTP is the HTTP client to use for requests. If this is nil, then
	// a default new HTTP client will be used.
	HTTP *http.Client

	// ListURL and DetailsURL are the URLs for listing licenses and accessing
	// a single license, respectively. If these are not set, they will default
	// to the default values specified in constants (i.e. DefaultListURL).
	//
	// For DetailsURL, use the placeholder "%[1]s" to interpolate the SPDX ID.
	ListURL    string
	DetailsURL string
	// contains filtered or unexported fields
}

Client is an API client for accessing SPDX data.

Configure any fields on the struct prior to calling any functions. After calling functions, do not access the fields again.

The functions on Client are safe to call concurrently.

func (*Client) License

func (c *Client) License(id string) (*LicenseInfo, error)

License returns the license by ID. This often includes more detailed information than List such as the full license text.

The ID is usually case sensitive. Please ensure the ID is set exactly to the SPDX ID, including casing.

If err == nil, then *License will always be non-nil.

func (*Client) List

func (c *Client) List() (*LicenseList, error)

List returns the list of licenses.

If err == nil, then *LicenseList will always be non-nil.

type LicenseInfo

type LicenseInfo struct {
	ID          string   `json:"licenseId"`
	Name        string   `json:"name"`
	Text        string   `json:"licenseText"`
	Deprecated  bool     `json:"isDeprecatedLicenseId"`
	OSIApproved bool     `json:"isOsiApproved"`
	SeeAlso     []string `json:"seeAlso"`
}

LicenseInfo is a single software license.

Basic descriptions are documented in the fields below. For a full description of the fields, see the official SPDX specification here: https://github.com/spdx/license-list-data/blob/master/accessingLicenses.md

func License

func License(id string) (*LicenseInfo, error)

License is the same as Client.License, but operates on DefaultClient.

type LicenseList

type LicenseList struct {
	// Version is the raw version string of the license list.
	Version string `json:"licenseListVersion"`

	// Licenses is the list of known licenses.
	Licenses []*LicenseInfo `json:"licenses"`
}

LicenseList is the structure for a list of licenses provided by the SPDX API

func List

func List() (*LicenseList, error)

List is the same as Client.List, but operates on DefaultClient.

func (*LicenseList) License

func (l *LicenseList) License(id string) *LicenseInfo

License looks up the license in the list with the given ID. If the license is not found, nil is returned.

Note that licenses in a LicenseList are usually missing fields such as Text. To fully populate a Licenese, call Client.Licence with the ID.

Jump to

Keyboard shortcuts

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