licenses

package
v0.0.0-...-56fc28d Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package licenses defines a base type and support functions for describing software licenses.

Index

Constants

View Source
const PerFileNotice = `
Copyright (C) {{date "2006"}} {{.Author}}. All Rights Reserved.
`

PerFileNotice is a generic per-file license statement that can be added to any license that does not have more specific language to recommend.

Variables

This section is empty.

Functions

func List

func List(f func(License))

List calls f for each registered license. Licenses are visited in lexicographic order by slug.

func Register

func Register(lic License)

Register records a new license in the registry, using its slug as a key. This function will panic if the license slug is empty, or if the slug is already registered to a different license.

Types

type Config

type Config struct {
	// The name of the author, to whom copyright is attributed.
	Author string

	// The name of the project to which the license is attached, if different
	// from the author. Example: "FreeBSD".
	Project string

	// The current time. The template can render this field using the "time" and
	// "date" functions provided in the function map.
	Time time.Time
}

Config carries parameters to be expanded by text templates for a license.

type Indenting

type Indenting func(*block) *block

An Indenting is a rule for indenting or commenting license text for insertion into a file. A nil Indenting leaves the input text unmodified.

func IComment

func IComment(first, rest, last string) Indenting

IComment constructs an Indenting that prefixes the lines of text with the given comment markers.

func IPrefix

func IPrefix(marker string) Indenting

IPrefix constructs an Indenting that prefixes each line of text with the specified marker.

type License

type License struct {
	// A human-readable name of the license.
	// For example: "Apache License, Version 2.0".
	Name string

	// A slug used to identify the license. This value must be unique across all
	// registered licenses. Good slug values should be short, ideally one word,
	// with no spaces.
	Slug string

	// A URL to a description of the license (optional).
	URL string

	// The text of the license (template, required).
	Text string

	// Additional license text that must be inserted into each file covered by
	// the license (template, optional).
	PerFile string
}

A License describes a software license.

A package that implements a license should call license.Register during init with a value of this type, suitably populated with values corresponding to the details of that license.

func Lookup

func Lookup(slug string) *License

Lookup returns the license information for the specified slug, or nil if no such license is registered.

func (*License) EditFile

func (lic *License) EditFile(f *os.File, c *Config, indent Indenting) error

EditFile edits the per file license text into f. If the license has no per-file text, this does nothing without error. The indent controls how the text is indented or commented; if indent == nil it is inserted verbatim.

func (*License) WriteText

func (lic *License) WriteText(w io.Writer, c *Config) error

WriteText renders the main license text to w.

Directories

Path Synopsis
Package apache describes the Apache software licenses.
Package apache describes the Apache software licenses.
Package bsd describes BSD software licenses.
Package bsd describes BSD software licenses.
Package cc describes Creative Commons software licenses.
Package cc describes Creative Commons software licenses.
Package gpl describes the GNU GPL software licenses.
Package gpl describes the GNU GPL software licenses.
Package mit describes "the" MIT software licenses.
Package mit describes "the" MIT software licenses.
Package unlicense describes the unlicense.
Package unlicense describes the unlicense.

Jump to

Keyboard shortcuts

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