config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowState

type AllowState int
const (
	StateUnknown AllowState = iota
	StateAllowed
	StateDenied
)

type Config

type Config struct {
	// Allow and Deny are the list of licenses that are allowed or disallowed,
	// respectively. The string value here can be either the license name
	// (case insensitive) or the SPDX ID (case insensitive).
	//
	// If a license is found that isn't in either list, then a warning is
	// emitted. If a license is in both deny and allow, then deny takes
	// priority.
	Allow []string `hcl:"allow,optional"`
	Deny  []string `hcl:"deny,optional"`

	// Override is a map that explicitly sets the license for the given
	// import path. The key is an import path (exact) and the value is
	// the name or SPDX ID of the license. Regardless, the value will
	// be set as both the name and SPDX ID, so SPDX IDs are recommended.
	Override map[string]string `hcl:"override,optional"`

	// Translate is a map that translates one import source into another.
	// For example, "gopkg.in/(.*)" => "github.com/\1" would translate
	// gopkg into github (incorrectly, but the example would work).
	Translate map[string]string `hcl:"translate,optional"`
}

Config is the configuration structure for the license checker.

func Parse

func Parse(r io.Reader, filename, format string) (*Config, error)

Parse parses the configuration from the given reader. The reader will be read to completion (EOF) before returning so ensure that the reader does not block forever.

format is either "hcl" or "json"

func ParseFile

func ParseFile(filename string) (*Config, error)

ParseFile parses the given file for a configuration. The syntax of the file is determined based on the filename extension: "hcl" for HCL, "json" for JSON, other is an error.

func (*Config) Allowed

func (c *Config) Allowed(l *license.License) AllowState

Allowed returns the allowed state of a license given the configuration.

Jump to

Keyboard shortcuts

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