license

package
v0.2.1-0...-f9fe6cd Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusWithContext

func StatusWithContext(ctx context.Context, l StatusListener) context.Context

StatusWithContext inserts a StatusListener into a context.

func Translate

func Translate(ctx context.Context, m module.Module, ts []Translator) module.Module

Translate translates the given module or returns the same module if no translation is necessary.

func UpdateStatus

func UpdateStatus(ctx context.Context, t StatusType, msg string)

UpdateStatus updates the status of the listener (if any) in the given context.

Types

type Finder

type Finder interface {
	// License looks up the license for a given module.
	License(context.Context, module.Module) (*License, error)
}

Finder implementations can find a license for a given module.

type License

type License struct {
	Name string // Name is a human-friendly name like "MIT License"
	SPDX string // SPDX ID of the license, blank if unknown or unavailable
}

License represents a software license.

func Find

func Find(ctx context.Context, m module.Module, fs []Finder) (r *License, rerr error)

Find finds the license for the given module using a set of finders.

The finders are tried in the order given. The first finder to return a non-nil License without an error is returned. If a finder returns an error, other finders are still attempted. It is possible for a non-nil license to be returned WITH a non-nil error meaning a different lookup failed.

func (*License) String

func (l *License) String() string

type MockFinder

type MockFinder struct {
	mock.Mock
}

MockFinder is an autogenerated mock type for the Finder type

func (*MockFinder) License

func (_m *MockFinder) License(_a0 context.Context, _a1 module.Module) (*License, error)

License provides a mock function with given fields: _a0, _a1

type MockStatusListener

type MockStatusListener struct {
	mock.Mock
}

MockStatusListener is an autogenerated mock type for the StatusListener type

func (*MockStatusListener) UpdateStatus

func (_m *MockStatusListener) UpdateStatus(t StatusType, msg string)

UpdateStatus provides a mock function with given fields: t, msg

type StatusListener

type StatusListener interface {
	// UpdateStatus is called whenever there is an updated status message.
	// This function must not block, since this will block the actual
	// behavior of the license finder as well. If blocking behavior is
	// necessary, end users should use a channel internally to avoid it on
	// the function call.
	//
	// The message should be relatively short if possible (within ~50 chars)
	// so that it fits nicely on a terminal. It should be a basic status
	// update.
	UpdateStatus(t StatusType, msg string)
}

StatusListener is called to update the status of a finder.

type StatusType

type StatusType uint

StatusType is the type of status message, such as normal, error, warning.

const (
	StatusUnknown StatusType = iota
	StatusNormal
	StatusWarning
	StatusError
)

type Translator

type Translator interface {
	// Translate takes a module and converts it into another module.
	// This is used to, for example, detect gopkg.in URLs as GitHub
	// repositories.
	Translate(context.Context, module.Module) (module.Module, bool)
}

Translator implementations can convert one module path to another module path that is more suitable for license lookup.

Directories

Path Synopsis
Package mapper contains a translator using a raw map[string]string
Package mapper contains a translator using a raw map[string]string

Jump to

Keyboard shortcuts

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