Documentation
¶
Overview ¶
Package license contains ecosystem-agnostic helpers for license classification, copyright extraction, and license-URL construction.
Index ¶
- func BuildURL(base, ref, licenseFile string) (string, error)
- func Classify(text []byte) ([]string, error)
- func ExtractCopyright(text []byte) ([]string, error)
- func ExtractCopyrightFromDir(dir string, licenseText []byte) ([]string, error)
- func FindFile(dir string) (string, error)
- func SPDXFriendly(spdx string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildURL ¶
BuildURL combines the repository base, ref, and license filename into a canonical blob URL. GitHub and GitLab share the `/blob/<ref>/<file>` shape; cs.opensource.google uses `/+/refs/tags/<ref>:<file>`; bitbucket uses `/src/<ref>/<file>`. Unknown forges fall through to the bare base URL.
func Classify ¶
Classify runs google/licensecheck against the LICENSE text and returns the friendly names of all matched licenses, in source-text order, deduplicated. Errors out if no license is recognized.
func ExtractCopyright ¶
ExtractCopyright pulls Copyright lines out of license text. Lines that look like license-text boilerplate (containing uppercase "COPYRIGHT HOLDER(S)" or "COPYRIGHT NOTICE") are ignored. Returns an error when no usable copyright line is found.
func ExtractCopyrightFromDir ¶
ExtractCopyrightFromDir tries to find copyright lines in the LICENSE text first, then falls back to a sibling NOTICE / AUTHORS / CONTRIBUTORS file in the same directory. If no copyright is found in any of those, returns a single-element placeholder pointing the reader at the LICENSE file (common for Apache-2.0 projects whose LICENSE is the stock boilerplate and whose copyright lives only in source-file headers).
func FindFile ¶
FindFile locates the canonical license file inside dir. It searches a fixed list of conventional names (LICENSE, LICENCE, COPYING, etc.) and returns the first hit. Returns an error if no candidate exists.
func SPDXFriendly ¶
SPDXFriendly converts an SPDX license identifier to its long human-readable name. Unknown identifiers and compound expressions ("MIT OR Apache-2.0") are reduced by taking the first known sub-expression; if nothing matches the input is returned unchanged.
Types ¶
This section is empty.