plugins

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilTemplate is thrown when a renderer plugin attempts an operation that cannot be performed
	// because the renderer's template has not been loaded.
	ErrNilTemplate = errors.New("renderer plugin has nil template")

	// ErrEmptyResult is thrown when a renderer plugin attempts to export the Result and finds no
	// data in it's buffer.
	ErrEmptyResult = errors.New("renderer plugin returned an empty result")
)

All returns a pre-populated list of plugins written for renum's code generator.

Functions

This section is empty.

Types

type Case

type Case int

Case is used to automate the creation of case specific values during rendering.

const (
	// CaseSnake represents snake_case
	CaseSnake Case = iota

	// CasePascal represents PascalCase
	CasePascal

	// CaseScreaming represents SCREAMING_CASE
	CaseScreaming

	// CaseCamel represents camelCase
	CaseCamel

	// CaseCommand represents command-case
	CaseCommand

	// CaseTrain represents TRAIN-CASE
	CaseTrain

	// CaseDotted represents dotted.case
	CaseDotted

	// CaseDefault is an alias to the default, snake_case
	CaseDefault = CaseSnake
)

func (Case) String

func (c Case) String() string

String returns the case as a string representation.

func (Case) Val

func (c Case) Val(e *config.Element) string

Val returns an enum element's identifier that matches the appropriate case.

type Constructor

type Constructor func() Plugin

Constructor is a type alias to denote the signature for creating plugins.

type GetterFunc

type GetterFunc func(e config.Element) interface{}

GetterFunc is a type alias to allow retrieval of element fields on the fly.

type Plugin

type Plugin interface {
	// Name returns the unique identifier of the plugin. This will be used
	// as the primary key in the renum generator renderer registry.
	Name() string

	// Load is called to provide the Plugin with it's Go template for codegen by the generator.
	Load(b []byte) error

	// Enabled is called to let a Plugin deterine if it should be used for this configuration.
	Enabled(c *config.Config) bool

	// Validate is used to ensure the configuration meets the requirements for this Plugin.
	Validate(c *config.Config) error

	// Render should construct the generated code, typically holding the result in a buffer.
	Render(c *config.Config) error

	// Result should return the buffer's data, or an error if an unexpected condition arises.
	Result() ([]byte, error)

	// Priority is used to determine the insertion order of the Result into the final generated code.
	Priority() int
}

Plugin defines how a plugin is constructed within Renum, allowing for the codegen to be based on a set of Plugin components. These then get executed in parallel, and have their result combined together.

func NewCSVPlugin

func NewCSVPlugin() Plugin

NewCSVPlugin creates a new renum generator plugin to implement csv.Marshaler and csv.Unmarshaler interfaces.

func NewCamelCasePlugin

func NewCamelCasePlugin() Plugin

NewCamelCasePlugin creates a new renum generator plugin to support camelCase enum strings.

func NewCoderPlugin

func NewCoderPlugin() Plugin

NewCoderPlugin creates a new renum generator plugin to support the renum.Coder interface.

func NewCommandCasePlugin

func NewCommandCasePlugin() Plugin

NewCommandCasePlugin creates a new renum generator plugin to support command-case enum strings.

func NewConstPlugin

func NewConstPlugin() Plugin

NewConstPlugin creates a new renum generator plugin to create the const enum definitions.

func NewDefinitionPlugin

func NewDefinitionPlugin() Plugin

NewDefinitionPlugin creates a new renum generator plugin to render the type alias for the renum.Enum base type.

func NewDescriptionerPlugin

func NewDescriptionerPlugin() Plugin

NewDescriptionerPlugin is used to create a renum generator plugin for implementing the renum.Descriptioner interface on enum types.

func NewDottedCasePlugin

func NewDottedCasePlugin() Plugin

NewDottedCasePlugin creates a new renum generator plugin to support dotted.case enum strings.

func NewErrorsPlugin

func NewErrorsPlugin() Plugin

NewErrorsPlugin creates a new renum generator plugin to implement the renum.Error interface on enum types.

func NewFlagsPlugin

func NewFlagsPlugin() Plugin

NewFlagsPlugin creates a new renum generator plugin to support golang flag.Value interface.

func NewHTTPCodesPlugin

func NewHTTPCodesPlugin() Plugin

NewHTTPCodesPlugin creates a new renum generator plugin to implement the renum.HTTPResponder interface.

func NewHeaderPlugin

func NewHeaderPlugin() Plugin

NewHeaderPlugin creates a new renum generator plugin to generate the package and import declaration on the generated code.

func NewJSONPlugin

func NewJSONPlugin() Plugin

NewJSONPlugin creates a new renum generator plugin to implement json.Marshaler and json.Unmarshaler interfaces.

func NewMessagesPlugin

func NewMessagesPlugin() Plugin

NewMessagesPlugin creates a new renum generator plugin to implement the error interface on enum types.

func NewNamesPlugin

func NewNamesPlugin() Plugin

NewNamesPlugin creates a new renum generator plugin to create a string slice of enum values.

func NewNamespacerPlugin

func NewNamespacerPlugin() Plugin

NewNamespacerPlugin creates a new renum generator plugin to implement the renum.Namespacer interface.

func NewOSExitCodesPlugin

func NewOSExitCodesPlugin() Plugin

NewOSExitCodesPlugin creates a new renum generator plugin to implement the renum.ProcessResponder interface.

func NewParsePlugin

func NewParsePlugin() Plugin

NewParsePlugin creates a new renum generator plugin to implement the required Parse{{Type}} function.

func NewPascalCasePlugin

func NewPascalCasePlugin() Plugin

NewPascalCasePlugin creates a new renum generator plugin to support PascalCase enum strings.

func NewSQLPlugin

func NewSQLPlugin() Plugin

NewSQLPlugin creates a new renum generator plugin to support the sql.Scanner and driver.Valuer interfaces.

func NewScreamingCasePlugin

func NewScreamingCasePlugin() Plugin

NewScreamingCasePlugin creates a new renum generator plugin to support SCREAMING_CASE enum strings.

func NewSnakeCasePlugin

func NewSnakeCasePlugin() Plugin

NewSnakeCasePlugin creates a new renum generator plugin to support snake_case enum strings.

func NewSourcerPlugin

func NewSourcerPlugin() Plugin

NewSourcerPlugin creates a new renum generator plugin to implement the renum.Sourcer interface.

func NewStringerPlugin

func NewStringerPlugin() Plugin

NewStringerPlugin creates a new renum generator plugin to support the fmt.Stringer interface.

func NewTextPlugin

func NewTextPlugin() Plugin

NewTextPlugin creates a new renum generator plugin to support the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces.

func NewTrainCasePlugin

func NewTrainCasePlugin() Plugin

NewTrainCasePlugin creates a new renum generator plugin to support TRAIN-CASE enum strings.

func NewTyperPlugin

func NewTyperPlugin() Plugin

NewTyperPlugin creates a new renum generator plugin to support the renum.Typer interface.

func NewValuesPlugin

func NewValuesPlugin() Plugin

NewValuesPlugin creates a new renum generator plugin to add a slice of possible enum values into the package.

func NewYAMLPlugin

func NewYAMLPlugin() Plugin

NewYAMLPlugin creates a new renum generator plugin to support the yaml.Marshaler and yaml.Unmarshaler interfaces.

func NewYARPCCodesPlugin

func NewYARPCCodesPlugin() Plugin

NewYARPCCodesPlugin creates a new renum generator plugin to support the renum.YARPCResponder interface.

type PluginList

type PluginList []Plugin

PluginList implements a slice for Plugins that can be sorted.

func (PluginList) Len

func (r PluginList) Len() int

Len implements the sort.Sort interface.

func (PluginList) Less

func (r PluginList) Less(i, j int) bool

Less implements the sort.Sort interface.

func (PluginList) Swap

func (r PluginList) Swap(i, j int)

Swap implements the sort.Sort interface.

type ValueType

type ValueType int

ValueType is an alias to help automate the construction of code generated maps for enum lookups.

const (
	// ValueTypeString is the default value type and is used to construct map[%s]string{} types.
	ValueTypeString ValueType = iota

	// ValueTypeInt is used to construct map[%s]int{} types.
	ValueTypeInt

	// ValueTypeYARPCError is used to construct map[%s]yarpcerrors.Code types.
	ValueTypeYARPCError
)

func (ValueType) FormatValue

func (v ValueType) FormatValue(buf io.Writer, values ...interface{}) (int, error)

FormatValue is used to return the format string appropriate for the type of map being built.

func (ValueType) String

func (v ValueType) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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