github.com/metasources/buildx@v0.0.0-20230418141019-7aa1459cedea/internal/spdxlicense/license.go (about) 1 package spdxlicense 2 3 import ( 4 "strings" 5 ) 6 7 // https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/#license-short-name 8 // License generated in license_list.go uses a regular expression to help resolve cases where 9 // x.0.0 and x are supplied as version numbers. For SPDX compatibility, versions with trailing 10 // dot-zeroes are considered to be equivalent to versions without (e.g., “2.0.0” is considered equal to “2.0” and “2”). 11 // EX: gpl-2+ ---> GPL-2.0+ 12 // EX: gpl-2.0.0-only ---> GPL-2.0-only 13 // See the debian link for more details on the spdx license differences 14 15 const ( 16 LicenseRefPrefix = "LicenseRef-" // prefix for non-standard licenses 17 ) 18 19 //go:generate go run ./generate 20 21 // ID returns the canonical license ID for the given license ID 22 // Note: this function is only concerned with returning a best match of an SPDX license ID 23 // SPDX Expressions will be handled by a parent package which will call this function 24 func ID(id string) (value string, exists bool) { 25 // first look for a canonical license 26 if value, exists := licenseIDs[cleanLicenseID(id)]; exists { 27 return value, exists 28 } 29 // we did not find, so treat it as a separate license 30 return "", false 31 } 32 33 func cleanLicenseID(id string) string { 34 id = strings.TrimSpace(id) 35 id = strings.ToLower(id) 36 return strings.ReplaceAll(id, "-", "") 37 }