Skip to content

📜 License

The cpeskills package models software licenses based on the SPDX license list standard, with helpers to construct, identify and inspect common licenses.

Type: License

go
type License struct {
    SPDXID       string   `json:"id"`
    Name         string   `json:"name"`
    URL          string   `json:"url,omitempty"`
    IsCopyleft   bool     `json:"isCopyleft"`
    IsOSIApproved bool    `json:"isOSIApproved"`
    Restrictions []string `json:"restrictions,omitempty"`
}

Represents a software license based on the SPDX license list standard.

FieldTypeJSONDescription
SPDXIDstringidSPDX license identifier (e.g. "MIT", "Apache-2.0", "GPL-3.0-only")
NamestringnameFull license name
URLstringurl,omitemptyLink to the license text
IsCopyleftboolisCopyleftWhether it is a Copyleft license
IsOSIApprovedboolisOSIApprovedWhether it is OSI approved
Restrictions[]stringrestrictions,omitemptyUsage restrictions

🆕 NewLicense

go
func NewLicense(spdxID, name string) *License

Creates a new license. IsOSIApproved and IsCopyleft are derived automatically from the SPDX ID.

ParameterTypeDescription
spdxIDstringThe SPDX license identifier
namestringThe full license name
ReturnTypeDescription
#1*LicenseA new License with OSI/Copyleft flags populated
go
lic := cpeskills.NewLicense("MIT", "MIT License")

🏷️ License.String

go
func (l *License) String() string

Returns the SPDX identifier of the license. Returns an empty string if the receiver is nil.

ReturnTypeDescription
#1stringThe SPDX ID
go
lic := cpeskills.NewLicense("Apache-2.0", "Apache License 2.0")
fmt.Println(lic.String()) // Apache-2.0

📚 CommonLicenses

go
func CommonLicenses() []*License

Returns a list of common licenses (MIT, Apache-2.0, BSD-3-Clause, BSD-2-Clause, GPL-3.0-only, GPL-3.0-or-later, LGPL-3.0-only, MPL-2.0, ISC, Unlicense).

ReturnTypeDescription
#1[]*LicenseCommon SPDX licenses
go
for _, lic := range cpeskills.CommonLicenses() {
    fmt.Println(lic.SPDXID)
}

🔍 DetectLicenseByName

go
func DetectLicenseByName(name string) *License

Detects a license from a human-readable name or SPDX ID (case-insensitive). Recognizes common aliases such as apache 2.0, bsd3, gpl3, cc0, etc. Returns nil if the name is not recognized.

ParameterTypeDescription
namestringThe license name or SPDX ID
ReturnTypeDescription
#1*LicenseThe detected license, or nil if unrecognized
go
lic := cpeskills.DetectLicenseByName("Apache 2.0")
if lic != nil {
    fmt.Println(lic.SPDXID) // Apache-2.0
}

🧭 License Detection

Released under the MIT License.