license

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package license contains ecosystem-agnostic helpers for license classification, copyright extraction, and license-URL construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildURL

func BuildURL(base, ref, licenseFile string) (string, error)

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

func Classify(text []byte) ([]string, error)

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

func ExtractCopyright(text []byte) ([]string, error)

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

func ExtractCopyrightFromDir(dir string, licenseText []byte) ([]string, error)

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

func FindFile(dir string) (string, error)

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

func SPDXFriendly(spdx string) string

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.

Jump to

Keyboard shortcuts

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