golicenses

package module
v0.0.0-...-73aab2c Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

golicenses

Go Reference Update

This is an experimental package to lookup the license for a Go package.

This is not guaranteed to work, to update regularly, or to continue to have the same API. At a minimum, I'll probably change the repo name if I can think of something better.

For example:

lic, _ := golicenses.Get("github.com/google/go-containerregistry")
fmt.Println(lic)

prints

Apache-2.0

This is based on the public BigQuery dataset provided by https://deps.dev/. See How are licenses determined? for more information.

This repo periodically queries the public dataset and regenerates licenses.csv, which is gzipped and //go:embeded into the package.

The result is a ~3MB dependency that can be loaded and queried in ~200ms the first time -- subsequent calls take microseconds.

There are almost certainly more optimizations that could improve both size and query time. PRs welcome!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// LoadTime is the time it took to load the dataset.
	// It is populated after the first call to Get.
	LoadTime time.Duration

	// NumRecords is the total number of records in the dataset.
	// It is populated after the first call to Get.
	NumRecords int

	ErrNotFound = errors.New("not found")
)

Functions

func Get

func Get(p string) (string, error)

Get returns the reported license for the package.

The first time Get is called, the dataset is loaded and parsed and stored in memory, populating LoadTime and NumRecords. Subsequent calls to Get read from memory.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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