notice

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package notice provides functionality to detect license and copyright information of go modules.

Index

Constants

View Source
const OptionsFileName string = ".gotice.json" // the default filename of the notice options file

Variables

View Source
var (
	ErrNoPath      = errors.New("environment variable GOPATH not found")
	ErrPathEmpty   = errors.New("environment variable GOPATH is empty")
	ErrModNotFound = errors.New("module not found in GOPATH")
)
View Source
var (
	RenderingName = map[uint]string{
		1: "text",
		2: "html",
	}

	RenderingValue = map[string]uint{
		"text": 1,
		"html": 2,
	}
)
View Source
var HtmlTemplate string // the built-in html template
View Source
var LicenseFiles = [...]string{
	"LICENSE",
	"LICENSE.txt",
	"LICENSE.md",
}

The possible file names of license files used to detect the license texts of go modules.

View Source
var MarkdownTemplate string // the built-in markdown template
View Source
var TextTemplate string // the built-in text template

Functions

func GetLicenseText

func GetLicenseText(modpath, modversion string) (string, error)

GetLicenseText reads the license text of the go module defined by the given module path and module version.

func WriteHtml added in v0.4.0

func WriteHtml(w io.Writer, tmpl string, n []Notice) error

WriteText generates the notice file and writes it to w using the html template tmpl.

func WriteOptions added in v0.3.0

func WriteOptions(w io.Writer, o *Options) error

WriteOptions writes the given options to the given writer w using the json format.

func WriteText added in v0.4.0

func WriteText(w io.Writer, tmpl string, n []Notice) error

WriteText generates the notice file and writes it to w using the text template tmpl.

Types

type Notice

type Notice struct {
	Path        string // The path of the module
	Version     string // The version of the module
	LicenseText string // The license text of the module
}

Notice encapsulates license and copyright information of a single go module.

func New

func New() *Notice

New returns an empty Notice.

type Options added in v0.3.0

type Options struct {
	Template  string    `json:"template"`  // the template that shall be used
	Rendering Rendering `json:"rendering"` // the rendering that shall be used`
}

Options represents options for generating a notice file.

func NewOptions added in v0.3.0

func NewOptions() *Options

NewOptions returns a new Options struct with default values.

func ReadOptions added in v0.3.0

func ReadOptions(r io.Reader) (*Options, error)

ReadOptions reads options from the reader r in the json format.

type Rendering added in v0.4.0

type Rendering int

Rendering represents the type of output rendering.

const (
	Text Rendering = iota + 1 // Rendering via text/template
	Html                      // Rendering via html/template
)

func ParseRendering added in v0.4.0

func ParseRendering(s string) (Rendering, error)

ParseRendering returns a Rendering based on the string s.

func (Rendering) MarshalJSON added in v0.4.0

func (r Rendering) MarshalJSON() ([]byte, error)

MarshalJSON returns r as the JSON encoding of r.

func (Rendering) String added in v0.4.0

func (r Rendering) String() string

String returns the string-representation.

func (*Rendering) UnmarshalJSON added in v0.4.0

func (r *Rendering) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *r to a copy of data.

Jump to

Keyboard shortcuts

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