thoth

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

README

thoth

thoth does something good.

Build Status Dependency Updateer codecov.io Go Report Card Quality Gate Status Apache V2 License GitHub Release GoDoc

Setup

  1. Search and replace thoth with your project name.
  2. Initialize go.mod file: go mod init github.com/xmidt-org/thoth
  3. Add org teams to project (Settings > Manage Access):
    • xmidt-org/admins with Admin role
    • xmidt-org/server-writers with Write role
  4. Manually create the first release. After v0.0.1 exists, other releases will be made by automation after the CHANGELOG is updated to reflect a new version header and nothing under the Unreleased header.
  5. For libraries:
    1. Add org workflows in dir .github/workflows: push, tag, and release. This can be done by going to the Actions tab for the repo on the github site.
    2. Remove the following files/dirs: .dockerignore, Dockerfile, Makefile, rpkg.macros, thoth.yaml, deploy/, and conf/.
  6. For applications:
    1. Remove PkgGoDev badge from this file.
    2. Add org workflows in dir .github/workflows: push, tag, release, and docker-release. This can be done by going to the Actions tab for the repo on the github site.
    3. Add project name, .ignore, and errors.txt to .gitignore file.
    4. Update Dockerfile - choose new ports to expose that no current XMiDT application is using.
    5. Update deploy/packaging/thoth.spec file to have a proper Summary and Description.
    6. Update conf/thoth.service file to have a proper Description.

Summary

Summary should be a small paragraph explanation of what this project does.

Table of Contents

Code of Conduct

This project and everyone participating in it are governed by the XMiDT Code Of Conduct. By participating, you agree to this Code.

Details

Add details here.

Install

Add details here.

Contributing

Refer to CONTRIBUTING.md.

Documentation

Index

Constants

View Source
const (
	MissingKeyInvalid = "invalid"
	MissingKeyDefault = "default"
	MissingKeyZero    = "zero"
	MissingKeyError   = "error"
	DefaultMissingKey = MissingKeyError
)
View Source
const DefaultMediaType = "application/json"

DefaultMediaType is the MIME type assumed when either an object does not implement MediaTyper or returns the empty string from its MediaType method.

Variables

View Source
var (
	// ErrStopSearch is a sentinel indicating that UpSearch should halt and return.
	ErrStopSearch = errors.New("sentinel error indicating a search should end")
)

Functions

func FirstFile

func FirstFile(result *string, info *fs.FileInfo, names ...string) func(string) error

FirstFile returns a predicate for UpSearch that matches the first file with any of a set of names. Upon any match, the returned predicate returns ErrStopSearch.

The result pointer must be non-nil and receives the absolute path of the first file matched. Info is optional, and if non-nil it receives the fs.FileInfo associated with the result path.

func MediaType

func MediaType(t Template) (mediaType string)

MediaType returns the MIME type associated with the given template. If no MIME type is associated with the template, DefaultMediaType is returned.

func UpSearch

func UpSearch(dir string, fns ...func(string) error) (err error)

UpSearch walks up a directory applying predicates to each absolute path. The given directory is walked up to the root. If any of the predicates return the special value ErrStopSearch, then UpSearch returns immediately with a nil error. Otherwise, any error halts the search and that error is returned.

Types

type InvalidMissingKeyError

type InvalidMissingKeyError struct {
	Value string
}

InvalidMissingKeyError indicates that an unrecognized value was used in configuration for MissingKey. The text/template and html/template packages will panic in this case, whereas this package uses this error.

func (*InvalidMissingKeyError) Error

func (imke *InvalidMissingKeyError) Error() string

Error satisfies the error interface.

type KeyValues

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

KeyValues is an immutable, efficient list of key/value pairs for enriching Models prior to template execution.

func (KeyValues) Append

func (kvs KeyValues) Append(more Model) KeyValues

Append adds key/value pairs to this list. If more is not empty, a new, distinct KeyValues is created and returned with the Model's key/value pairs added. If more is empty, this KeyValues is returned.

Duplicate keys are allowed. The final value of that key is simply the value last added to this list.

This method does not modify this instance.

func (KeyValues) ApplyDefaults

func (kvs KeyValues) ApplyDefaults(m Model)

ApplyDefaults uses the key/value pairs in this list as defaults for the given model. Any key present in this list but not present in the model will be set to the value in this list. Existing keys in the model that are not in this list are left untouched.

func (KeyValues) ApplyOverrides

func (kvs KeyValues) ApplyOverrides(m Model)

ApplyOverrides unconditionally sets each key in this list on the given model. Existing keys in the model that are in this list are overridden.

func (KeyValues) Extend

func (kvs KeyValues) Extend(more KeyValues) KeyValues

Extend adds the key/value pairs in another list to this list. If more is empty, this instance is returned. If this instance is empty, then more is returned. Otherwise, a new, distinct KeyValues is returned that is the merge of the two.

Duplicate keys are allowed. The final value of that key is simply the value last added to this list.

This method does not modify this instance.

type Matcher

type Matcher interface {
	Match(string) bool
}

Matcher is a simple strategy for matching values, such as names and paths.

func ParsePatterns

func ParsePatterns(patterns ...string) (Matcher, error)

ParsePatterns parses a sequence of globs for matching values. The returned Matcher will match values if at least one of the globs matched. If patterns is empty, then the returned Matcher won't match anything.

type Matchers

type Matchers []Matcher

Matchers is an aggregate Matcher. A value will match if any of the sequence of Matchers returns true.

func (Matchers) Match

func (ms Matchers) Match(v string) bool

type MediaTyper

type MediaTyper interface {
	// MediaType returns the MIME type associated with this object.  If
	// this method returns the empty string, then DefaultMediaType is assumed.
	MediaType() string
}

MediaTyper is an optional interface that associates a MIME type with an object. Typically, this interface is implemented by templates produced by this package to indicate what the MIME type of the rendered template is.

type Model

type Model map[string]interface{}

Model is a template model.

type Parser

type Parser interface {
	// Parse produces a Template from some parsed content.  The name is
	// optional, and can be the empty string.
	//
	// If a common Model was defined in ParserConfig, the returned Template
	// will also implement ModelTemplate.
	//
	// For golang templates, an internal prototype template is first cloned
	// and then used as the containing template for each parsed template.  This
	// ensures that every template is unaffected by global definitions in other templates.
	Parse(name, content string) (Template, error)
}

Parser is a template parser. A ParserConfig defines all the options for tailoring a Parser as desired.

func NewParser

func NewParser(c ParserConfig) (Parser, error)

NewParser creates a Parser from a set of configuration options. Templates returned by the parser created by this function will also implement MediaTyper, which will associated each Template with the media type specified in the config.

type ParserConfig

type ParserConfig struct {
	// HTML indicates which template package to use.  If this field is false,
	// which is the default, text/template is used by the returned Parser.
	// If this field is true, html/template is used instead.
	HTML bool `json:"html" yaml:"html"`

	// MissingKey is the "missingkey=..." option.  If unset, error is used.
	// If this field is set to an unrecognized value, an error is raised.
	MissingKey string `json:"missingKey" yaml:"missingKey"`

	// LeftDelim is the left delimiter for pipelines.  If unset, the default "{{" is used.
	LeftDelim string `json:"leftDelim" yaml:"leftDelim"`

	// RightDelim is the right delimiter for pipelines.  If unset, the default "}}" is used.
	RightDelim string `json:"rightDelim" yaml:"rightDelim"`

	// FuncMap is the function map for all templates returned by the Parser.
	FuncMap map[string]interface{} `json:"-" yaml:"-"`

	// MediaType is the media type associated with all rendered templates produced
	// by this parser configuration.  If unset, DefaultMediaType is assumed.
	MediaType string `json:"mediaType" yaml:"mediaType"`
}

ParserConfig is the set of configurable options for building a Parser.

type Selector

type Selector interface {
	// Select chooses a parser based on the template name.  If no parser
	// was found for the template, this method returns (nil, false).
	Select(name string) (Parser, bool)
}

Selector is a strategy for determining how to parse a template based on that template's name. The name is typically a relative path, which may be matched via globbing.

func NewSelector

func NewSelector(configs ...SelectorConfig) (Selector, error)

NewSelector constructs a Selector based on the given configurations. If an empty configs is passed, the returned Selector won't match any template names.

type SelectorConfig

type SelectorConfig struct {
	// Patterns are the globs which must match a template's name in order
	// to use this configured parser.
	Patterns []string `json:"patterns" yaml:"patterns"`

	// Parser is the configuration for parsing templates that match any
	// of the configured patterns.
	Parser ParserConfig `json:"parser" yaml:"parser"`
}

SelectorConfig represents a set of templates whose relative paths match one or more patterns.

type Template

type Template interface {
	// Name returns the name of this template supplied at parse time.  This will
	// typically be the relative path of this template.
	Name() string

	// Execute renders this template using the supplied data.  The type of
	// data is unspecified and is dependent on the underlying template.
	Execute(output io.Writer, data interface{}) error
}

Template represents a parsed template. The golang text and HTML templates implement this interface.

func MediaTemplate

func MediaTemplate(t Template, mediaType string) Template

MediaTemplate associates a Template, typically a raw golang template, with a MIME type. The returned Template will also implement MediaTyper.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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