license

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: MIT Imports: 6 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 = errors.New("license not found")

ErrNotFound is returned by the Adapter if a license cannot be found via the GitHub Licenses API.

Functions

func ResolvePlaceholders

func ResolvePlaceholders(text string, fieldMap FieldMap) string

ResolvePlaceholders takes a text and a field map and resolves all placeholders to the replacement values in the map.

Types

type Client

type Client struct {
	GitHubLicensesService
}

Client fetches license information from the GitHub Licenses API Service.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient creates a new *Client which will use httpClient for making http requests. If httpClient is nil, http.DefaultClient will be used instead.

func (*Client) GetLicense

func (c *Client) GetLicense(ctx context.Context, name string) (*Info, error)

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

func (*Client) ListLicenses

func (c *Client) ListLicenses(ctx context.Context) ([]*Info, error)

ListLicenses 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 FieldMap

type FieldMap map[string]string

FieldMap is a map of placeholder field name and replacement values.

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.

Jump to

Keyboard shortcuts

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