license

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package license provides an adapter to fetch license texts from the GitHub Licenses API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned by the Adapter if a license cannot be
	// found via the GitHub Licenses API.
	ErrNotFound = errors.New("license not found")

	// DefaultAdapter is the default adapter for the GitHub Licenses API.
	DefaultAdapter = NewAdapter(github.NewClient(nil).Licenses)
)

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter adapts to the GitHub Licences API.

func NewAdapter

func NewAdapter(service GitHubLicensesService) *Adapter

NewAdapter creates a new *Adapter for service.

func (*Adapter) Get

func (f *Adapter) Get(name string) (*Info, error)

Get fetches the info for the license with name. Will return ErrNotFound if the license is not recognized.

func (*Adapter) List

func (f *Adapter) List() ([]*Info, error)

List lists the infos for all available licenses. These do not include the license body but only the metadata. Use Get to fetch the body of a particular license.

type GitHubLicensesService

type GitHubLicensesService interface {
	Get(ctx context.Context, licenseName string) (*github.License, *github.Response, error)
	List(ctx context.Context) ([]*github.License, *github.Response, error)
}

GitHubLicensesService is the interface of the GitHub Licenses API Service.

type Info

type Info struct {
	Key  string
	Name string
	Body string
}

Info holds information about a single license.

func Get

func Get(name string) (*Info, error)

Get fetches the info for the license with name using the DefaultAdapter. Will return ErrNotFound if the license is not recognized.

func List

func List() ([]*Info, error)

List lists the infos for all available licenses using the DefaultAdapter. These do not include the license body but only the metadata. Use Get to fetch the body of a particular license.

Jump to

Keyboard shortcuts

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