gen

package
v0.0.0-...-48c028d Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: MIT Imports: 12 Imported by: 22

README

Gen

Gen is a package that provides code generation using functional compoistion of functions, where each is built around the concept of composable io.WriterTo. Each writer wraps the passed content of the next writer creating flexible structures for generating code or text easily.

Code Generation Structures

This package provides sets of structures which define specific code structures and are used to built a programmatically combination that define the expected code to be produced. It also provides a functional composition style functions that provide a cleaner and more descriptive approach to how these blocks are combined.

The code gen is heavily geared towards the use of text/template but also ensures to be flexible to provide non-template based structures that work as well.

Example

  • Generate a struct with moz
import "github.com/influx6/moz/gen"

floppy := gen.Struct(
		gen.Name("Floppy"),
		gen.Commentary(
			gen.Text("Floppy provides a basic function."),
			gen.Text("Demonstration of using floppy API."),
		),
		gen.Annotations(
			"Flipo",
			"API",
		),
		gen.Field(
			gen.Name("Name"),
			gen.Type("string"),
			gen.Tag("json", "name"),
		),
)

var source bytes.Buffer

floppy.WriteTo(&source) /*
// Floppy provides a basic function.
//
// Demonstration of using floppy API.
//
//
//@Flipo
//@API
type Floppy struct {

    Name string `json:"name"`

}
*/
  • Generate a function with moz
import "github.com/influx6/moz/gen"

main := gen.Function(
    gen.Name("main"),
    gen.Constructor(
        gen.FieldType(
            gen.Name("v"),
            gen.Type("int"),
        ),
        gen.FieldType(
            gen.Name("m"),
            gen.Type("string"),
        ),
    ),
    gen.Returns(),
    gen.SourceText(`	fmt.Printf("Welcome to Lola Land");`, nil),
)

var source bytes.Buffer

main.WriteTo(&source) /*
func main(v int, m string) {
	fmt.Printf("Welcome to Lola Land");
}
*/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommaWriter defines the a writer that consistently writes a ','.
	CommaWriter = NewConstantWriter([]byte(","))

	// NewlineWriter defines the a writer that consistently writes a \n.
	NewlineWriter = NewConstantWriter([]byte("\n"))

	// CommaSpacedWriter defines the a writer that consistently writes a ', '.
	CommaSpacedWriter = NewConstantWriter([]byte(", "))

	// PeriodWriter defines the a writer that consistently writes a '.'.
	PeriodWriter = NewConstantWriter([]byte("."))
)
View Source
var (
	PlusOperator           = OperatorDeclr{Operation: "+"}
	MinusOperator          = OperatorDeclr{Operation: "-"}
	ModeOperator           = OperatorDeclr{Operation: "%"}
	DivideOperator         = OperatorDeclr{Operation: "/"}
	MultiplicationOperator = OperatorDeclr{Operation: "*"}
	EqualOperator          = OperatorDeclr{Operation: "=="}
	LessThanOperator       = OperatorDeclr{Operation: "<"}
	MoreThanOperator       = OperatorDeclr{Operation: ">"}
	LessThanEqualOperator  = OperatorDeclr{Operation: "<="}
	MoreThanEqualOperator  = OperatorDeclr{Operation: ">="}
	NotEqualOperator       = OperatorDeclr{Operation: "!="}
	ANDOperator            = OperatorDeclr{Operation: "&&"}
	OROperator             = OperatorDeclr{Operation: "||"}
	BinaryANDOperator      = OperatorDeclr{Operation: "&"}
	BinaryOROperator       = OperatorDeclr{Operation: "|"}
	DecrementOperator      = OperatorDeclr{Operation: "--"}
	IncrementOperator      = OperatorDeclr{Operation: "++"}
)

Contains different sets of operator declarations.

View Source
var CommaMapper = MapAny{MapFn: func(to io.Writer, declrs ...io.WriterTo) (int64, error) {
	wc := NewWriteCounter(to)

	total := len(declrs) - 1

	for index, declr := range declrs {
		if _, err := declr.WriteTo(wc); err != nil && err != io.EOF {
			return 0, err
		}

		if index < total {
			CommaWriter.WriteTo(wc)
		}
	}

	return wc.Written(), nil
}}

CommaMapper defines a struct which implements the DeclarationMap which maps a set of items by seperating their output with a coma ',', but execludes before the first and after the last item.

View Source
var CommaSpacedMapper = MapAny{MapFn: func(to io.Writer, declrs ...io.WriterTo) (int64, error) {
	wc := NewWriteCounter(to)

	total := len(declrs) - 1

	for index, declr := range declrs {
		if _, err := declr.WriteTo(wc); err != nil && err != io.EOF {
			return 0, err
		}

		if index < total {
			CommaSpacedWriter.WriteTo(wc)
		}
	}

	return wc.Written(), nil
}}

CommaSpacedMapper defines a struct which implements the DeclarationMap which maps a set of items by seperating their output with a coma ', ', but execludes before the first and after the last item.

View Source
var DotMapper = MapAny{MapFn: func(to io.Writer, declrs ...io.WriterTo) (int64, error) {
	wc := NewWriteCounter(to)

	total := len(declrs) - 1

	for index, declr := range declrs {
		if _, err := declr.WriteTo(wc); err != nil && err != io.EOF {
			return 0, err
		}

		if index < total {
			PeriodWriter.WriteTo(wc)
		}
	}

	return wc.Written(), nil
}}

DotMapper defines a struct which implements the DeclarationMap which maps a set of items by seperating their output with a period '.', but execludes before the first and after the last item.

View Source
var NewlineMapper = MapAny{MapFn: func(to io.Writer, declrs ...io.WriterTo) (int64, error) {
	wc := NewWriteCounter(to)

	total := len(declrs) - 1

	for index, declr := range declrs {
		if _, err := declr.WriteTo(wc); err != nil && err != io.EOF {
			return 0, err
		}

		if index < total {
			NewlineWriter.WriteTo(wc)
		}
	}

	return wc.Written(), nil
}}

NewlineMapper defines a struct which implements the DeclarationMap which maps a set of items by seperating their output with a period '.', but execludes before the first and after the last item.

Functions

func Annotations

func Annotations(names ...string) io.WriterTo

Annotations returns a slice instance of io.WriterTo.

func Fmt

func Fmt(txt string, fm ...interface{}) io.WriterTo

Fmt returns a io.WriteTo which is formated using the fmt.Sprintf.

func IsDrainError

func IsDrainError(err error) bool

IsDrainError is used to check if a error value matches io.EOF.

func IsNoError

func IsNoError(err error) bool

IsNoError returns true/false if the error is nil.

func IsNotDrainError

func IsNotDrainError(err error) bool

IsNotDrainError is used to check if a error value matches io.EOF.

func ToTemplate

func ToTemplate(name string, templ string, mx template.FuncMap) (*template.Template, error)

ToTemplate returns a template instance with the giving templ string and functions.

func ToTemplateFuncs

func ToTemplateFuncs(funcs ...map[string]interface{}) template.FuncMap

ToTemplateFuncs returns a template.FuncMap which is a union of all key and values from the provided map. It does not check for function type and will override any previos key values.

Types

type AnnotationDeclr

type AnnotationDeclr struct {
	Value string `json:"value"`
}

AnnotationDeclr defines a struct for generating a annotation.

func Annotation

func Annotation(name string) AnnotationDeclr

Annotation returns a new instance of a AnnotationDeclr.

func (AnnotationDeclr) String

func (n AnnotationDeclr) String() string

String returns the internal name associated with the NameDeclr.

func (AnnotationDeclr) WriteTo

func (n AnnotationDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type BlockDeclr

type BlockDeclr struct {
	Block     io.WriterTo `json:"block"`
	RuneBegin rune        `json:"begin"`
	RuneEnd   rune        `json:"end"`
}

BlockDeclr defines a declaration which produces a block cover which wraps any other declaration writer into it's block char. eg. A BlockDeclr with Char '{”}'

Will produce '{DataFROMWriter}' output.

func Block

func Block(elems ...io.WriterTo) BlockDeclr

Block returns a new instance of a BlockDeclr with no prefix and suffix.

func WrapBlock

func WrapBlock(begin, end rune, elems ...io.WriterTo) BlockDeclr

WrapBlock returns a new instance of a BlockDeclr.

func (BlockDeclr) WriteTo

func (b BlockDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type BoolDeclr

type BoolDeclr struct {
	Value bool `json:"value"`
}

BoolDeclr defines a declaration struct for representing a giving value.

func Bool

func Bool(rn bool) BoolDeclr

Bool returns a new instance of a BoolDeclr.

func (BoolDeclr) String

func (n BoolDeclr) String() string

String returns the internal data associated with the structure.

func (BoolDeclr) WriteTo

func (n BoolDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type ByteBlockDeclr

type ByteBlockDeclr struct {
	Block      io.WriterTo `json:"block"`
	BlockBegin []byte      `json:"begin"`
	BlockEnd   []byte      `json:"end"`
}

ByteBlockDeclr defines a declaration which produces a block cover which wraps any other declaration writer into it's block char. eg. A BlockDeclr with Char '{”}'

Will produce '{{DataFROMWriter}}' output.

func ByteWrapBlock

func ByteWrapBlock(begin, end []byte, elems ...io.WriterTo) ByteBlockDeclr

ByteWrapBlock returns a new instance of a ByteBlockDeclr.

func (ByteBlockDeclr) WriteTo

func (b ByteBlockDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type CaseDeclr

type CaseDeclr struct {
	Condition io.WriterTo
	Behaviour io.WriterTo
}

CaseDeclr defines a structure which generates switch case declarations.

func Case

func Case(condition, action io.WriterTo) CaseDeclr

Case returns a new instance of a CaseDeclr.

func (CaseDeclr) WriteTo

func (c CaseDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the structure declaration.

type CommentDeclr

type CommentDeclr struct {
	MainBlock io.WriterTo `json:"mainBlock"`
	Blocks    WritersTo   `json:"blocks"`
}

CommentDeclr defines a declaration struct for representing a single comment.

func Commentary

func Commentary(mainblock io.WriterTo, elems ...io.WriterTo) CommentDeclr

Commentary returns a new instance of a CommentDeclr.

func (CommentDeclr) WriteTo

func (n CommentDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type ConditionDeclr

type ConditionDeclr struct {
	PreVar   VariableNameDeclr `json:"prevar"`
	PostVar  VariableNameDeclr `json:"postvar"`
	Operator OperatorDeclr     `json:"operator"`
}

ConditionDeclr defines a declaration which produces a variable declaration.

func Condition

Condition returns a new instance of a ConditionDeclr.

func (ConditionDeclr) WriteTo

func (c ConditionDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type ConstantWriter

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

ConstantWriter defines a writer that consistently writes a provided output.

func NewConstantWriter

func NewConstantWriter(d []byte) ConstantWriter

NewConstantWriter returns a new instance of ConstantWriter.

func (ConstantWriter) WriteTo

func (cw ConstantWriter) WriteTo(w io.Writer) (int64, error)

WriteTo writes the data provided into the writer.

type ConstructorDeclr

type ConstructorDeclr struct {
	Arguments []VariableTypeDeclr `json:"constructor"`
}

ConstructorDeclr defines a declaration which produces argument based output of it's giving internals.

func Constructor

func Constructor(args ...VariableTypeDeclr) ConstructorDeclr

Constructor returns a new instance of a ConstructorDeclr.

func (ConstructorDeclr) WriteTo

func (f ConstructorDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the function argument declaration.

type CustomReturnDeclr

type CustomReturnDeclr struct {
	Returns WritersTo `json:"returns"`
}

CustomReturnDeclr defines a declaration which produces argument based output of it's giving internals.

func CustomReturns

func CustomReturns(returns ...io.WriterTo) CustomReturnDeclr

CustomReturns returns a new instance of a CustomReturnDeclr.

func (CustomReturnDeclr) WriteTo

func (f CustomReturnDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the function argument declaration.

type DefaultCaseDeclr

type DefaultCaseDeclr struct {
	Behaviour io.WriterTo
}

DefaultCaseDeclr defines a structure which generates switch default case declarations.

func DefaultCase

func DefaultCase(action io.WriterTo) DefaultCaseDeclr

DefaultCase returns a new instance of a DefaultCaseDeclr.

func (DefaultCaseDeclr) WriteTo

func (c DefaultCaseDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the structure declaration.

type FieldTypeDeclr

type FieldTypeDeclr struct {
	Name NameDeclr `json:"name"`
	Type TypeDeclr `json:"typename"`
}

FieldTypeDeclr defines a declaration which produces a variable declaration.

func FieldType

func FieldType(name NameDeclr, ntype TypeDeclr) FieldTypeDeclr

FieldType returns a new instance of a VariableTypeDeclr.

func (FieldTypeDeclr) WriteTo

func (v FieldTypeDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type Float32Declr

type Float32Declr struct {
	Value float32 `json:"value"`
}

Float32Declr defines a declaration struct for representing a giving value.

func Float32

func Float32(rn float32) Float32Declr

Float32 returns a new instance of a Float32.

func (Float32Declr) String

func (n Float32Declr) String() string

String returns the internal data associated with the structure.

func (Float32Declr) WriteTo

func (n Float32Declr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type Float64Declr

type Float64Declr struct {
	Value float64 `json:"value"`
}

Float64Declr defines a declaration struct for representing a giving value.

func Float64

func Float64(rn float64) Float64Declr

Float64 returns a new instance of a Float64.

func (Float64Declr) String

func (n Float64Declr) String() string

String returns the internal data associated with the structure.

func (Float64Declr) WriteTo

func (n Float64Declr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type FloatBaseDeclr

type FloatBaseDeclr struct {
	Value     float64 `json:"value"`
	Bitsize   int     `json:"base"`
	Precision int     `json:"precision"`
}

FloatBaseDeclr defines a declaration struct for representing a giving value.

func FloatBase

func FloatBase(rn float64, bit, prec int) FloatBaseDeclr

FloatBase returns a new instance of a FloatBaseDeclr.

func (FloatBaseDeclr) String

func (n FloatBaseDeclr) String() string

String returns the internal data associated with the structure.

func (FloatBaseDeclr) WriteTo

func (n FloatBaseDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type FromReader

type FromReader struct {
	R             io.Reader
	ReadBlockSize int
}

FromReader implements io.WriterTo by wrapping a provided io.Reader.

func (*FromReader) WriteTo

func (fm *FromReader) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type FunctionDeclr

type FunctionDeclr struct {
	Name        NameDeclr        `json:"name"`
	Constructor ConstructorDeclr `json:"constructor"`
	Returns     io.WriterTo      `json:"returns"`
	Body        WritersTo        `json:"body"`
}

FunctionDeclr defines a declaration which produces function about based on the giving constructor and body.

func Function

func Function(name NameDeclr, constr ConstructorDeclr, returns io.WriterTo, body ...io.WriterTo) FunctionDeclr

Function returns a new instance of a FunctionDeclr.

func (FunctionDeclr) WriteTo

func (f FunctionDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the function declaration.

type FunctionTypeDeclr

type FunctionTypeDeclr struct {
	Name        NameDeclr        `json:"name"`
	Constructor ConstructorDeclr `json:"constructor"`
	Returns     io.WriterTo      `json:"returns"`
}

FunctionTypeDeclr defines a declaration which produces function about based on the giving constructor and body.

func FunctionType

func FunctionType(name NameDeclr, constr ConstructorDeclr, returns io.WriterTo) FunctionTypeDeclr

FunctionType returns a new instance of a FunctionTypeDeclr.

func (FunctionTypeDeclr) WriteTo

func (f FunctionTypeDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the function declaration.

type IfDeclr

type IfDeclr struct {
	Condition io.WriterTo
	Action    io.WriterTo
}

IfDeclr defines a type to represent a if condition.

func If

func If(condition, action io.WriterTo) IfDeclr

If returns a new instance of a IfDeclr.

func (IfDeclr) WriteTo

func (c IfDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the structure declaration.

type ImportDeclr

type ImportDeclr struct {
	Packages []ImportItemDeclr `json:"packages"`
}

ImportDeclr defines a type to represent a import statement.

func Imports

func Imports(ims ...ImportItemDeclr) ImportDeclr

Imports returns a new instance of a ImportDeclr.

func (ImportDeclr) WriteTo

func (im ImportDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the structure declaration.

type ImportItemDeclr

type ImportItemDeclr struct {
	Path      string `json:"path"`
	Namespace string `json:"namespace"`
}

ImportItemDeclr defines a type to represent a import statement.

func Import

func Import(path string, namespace string) ImportItemDeclr

Import returns a new instance of a ImportItemDeclr.

func (ImportItemDeclr) WriteTo

func (im ImportItemDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the structure declaration.

type Int32Declr

type Int32Declr struct {
	Value int32 `json:"value"`
}

Int32Declr defines a declaration struct for representing a giving value.

func Int32

func Int32(rn int32) Int32Declr

Int32 returns a new instance of a Int32Declr.

func (Int32Declr) String

func (n Int32Declr) String() string

String returns the internal data associated with the structure.

func (Int32Declr) WriteTo

func (n Int32Declr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type Int64Declr

type Int64Declr struct {
	Value int64 `json:"value"`
}

Int64Declr defines a declaration struct for representing a giving value.

func Int64

func Int64(rn int64) Int64Declr

Int64 returns a new instance of a Int64Declr.

func (Int64Declr) String

func (n Int64Declr) String() string

String returns the internal data associated with the structure.

func (Int64Declr) WriteTo

func (n Int64Declr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type IntBaseDeclr

type IntBaseDeclr struct {
	Value int64 `json:"value"`
	Base  int   `json:"base"`
}

IntBaseDeclr defines a declaration struct for representing a giving value.

func IntBase

func IntBase(rn int64, base int) IntBaseDeclr

IntBase returns a new instance of a UIntBaseDeclr.

func (IntBaseDeclr) String

func (n IntBaseDeclr) String() string

String returns the internal data associated with the structure.

func (IntBaseDeclr) WriteTo

func (n IntBaseDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type IntDeclr

type IntDeclr struct {
	Value int `json:"value"`
}

IntDeclr defines a declaration struct for representing a giving value.

func Int

func Int(rn int) IntDeclr

Int returns a new instance of a IntDeclr.

func (IntDeclr) String

func (n IntDeclr) String() string

String returns the internal data associated with the structure.

func (IntDeclr) WriteTo

func (n IntDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type JSONBlock

type JSONBlock struct {
	Items map[string]io.WriterTo
}

JSONBlock defines a block area which is encycled by braces.

{
	...
}

func JSONDocument

func JSONDocument(contents map[string]io.WriterTo) JSONBlock

JSONDocument returns a JSONBlock and uses the contents for the JSON document.

func (JSONBlock) WriteTo

func (v JSONBlock) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type JSONDeclr

type JSONDeclr struct {
	Documents []io.WriterTo
}

JSONDeclr defines a block area contains other JSONBlocks.

{
	  {
		...
	   }
}

func JSON

func JSON(documents ...io.WriterTo) JSONDeclr

JSON returns a new instance of a JSONDeclr.

func (JSONDeclr) WriteTo

func (m JSONDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type MapAny

type MapAny struct {
	MapFn MapOut
}

MapAny defines a struct which implements a structure which uses the provided int64ernal MapOut function to apply the necessary business logic of copying giving data space by a giving series of readers.

func (MapAny) Map

func (mapper MapAny) Map(dls ...io.WriterTo) io.WriterTo

Map takes a giving set of readers returning a structure which implements the io.Reader int64erface for copying underlying data to the expected output.

type MapAnyWriter

type MapAnyWriter struct {
	Map MapOut
	Dcl []io.WriterTo
}

MapAnyWriter applies a giving set of MapOut functions with the provided int64ernal declarations writes to the provided io.Writer.

func (MapAnyWriter) WriteTo

func (m MapAnyWriter) WriteTo(to io.Writer) (int64, error)

WriteTo takes the data slice and writes int64ernal WritersTo int64o the giving writer.

type MapDeclr

type MapDeclr struct {
	Type    NameDeclr
	Value   NameDeclr
	MapType io.WriterTo
	Values  map[string]io.WriterTo
}

MapDeclr defines a type for a map declaration.

func Map

func Map(mapkeyType string, mapkeyValue string, values map[string]io.WriterTo) MapDeclr

Map returns a MapDeclr for creating a map definition with values for the specific key-value pairs

func TMap

func TMap(mapType string, mapkeyType string, mapkeyValue string, values map[string]io.WriterTo) MapDeclr

TMap returns a MapDeclr for creating a map definition with values for the specific key-value pairs

func (MapDeclr) WriteTo

func (tx MapDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type MapOut

type MapOut func(io.Writer, ...io.WriterTo) (int64, error)

MapOut defines an function type which maps giving data retrieved from a series of readers int64o the provided byte slice, returning the total number of data written and any error encountered.

type MultiCommentDeclr

type MultiCommentDeclr struct {
	MainBlock io.WriterTo `json:"mainBlock"`
	Blocks    WritersTo   `json:"blocks"`
}

MultiCommentDeclr defines a declaration struct for representing a single comment.

func MultiComments

func MultiComments(mainblock io.WriterTo, elems ...io.WriterTo) MultiCommentDeclr

MultiComments returns a new instance of a MultiCommentDeclr.

func (MultiCommentDeclr) WriteTo

func (n MultiCommentDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type NameDeclr

type NameDeclr struct {
	Name string `json:"name"`
}

NameDeclr defines a declaration struct for representing a giving value.

func FmtName

func FmtName(name string, vals ...interface{}) NameDeclr

FmtName returns a new instance of a NameDeclr aftering passing the string with the values using fmt.

func Name

func Name(name string) NameDeclr

Name returns a new instance of a NameDeclr.

func (NameDeclr) String

func (n NameDeclr) String() string

String returns the internal name associated with the NameDeclr.

func (NameDeclr) WriteTo

func (n NameDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type NoBOMWriter

type NoBOMWriter struct {
	io.Writer
}

NoBOMWriter removes any unwanted characters like \x00 found in possible code.

func NewNoBOM

func NewNoBOM(w io.Writer) *NoBOMWriter

NewNoBOM returns a new instance of the NoBOMWriter

func (*NoBOMWriter) Write

func (bom *NoBOMWriter) Write(b []byte) (int, error)

Write writes the bytes provided after removing such any \x00 characters.

type OperatorDeclr

type OperatorDeclr struct {
	Operation string `json:"operation"`
}

OperatorDeclr defines a declaration which produces a variable declaration.

func Ops

func Ops(ty string) OperatorDeclr

Ops returns a new instance of a OperatorDeclr.

func (OperatorDeclr) String

func (n OperatorDeclr) String() string

String returns the internal name associated with the struct.

func (OperatorDeclr) WriteTo

func (n OperatorDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type PackageDeclr

type PackageDeclr struct {
	Name io.WriterTo `json:"name"`
	Body WritersTo   `json:"body"`
}

PackageDeclr defines a declaration which generates a go package source.

func Package

func Package(name io.WriterTo, dirs ...io.WriterTo) PackageDeclr

Package returns a new instance of a PackageDeclr.

func (PackageDeclr) WriteTo

func (pkg PackageDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type PrefixDeclr

type PrefixDeclr struct {
	Prefix io.WriterTo `json:"-"`
	Value  io.WriterTo `json:"-"`
}

PrefixDeclr defines a declaration which produces a block with the provided prefix.

func Prefix

func Prefix(prefix, val io.WriterTo) PrefixDeclr

Prefix returns a new instance of a PrefixDeclr.

func (PrefixDeclr) WriteTo

func (b PrefixDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type ReturnDeclr

type ReturnDeclr struct {
	Returns []TypeDeclr `json:"returns"`
}

ReturnDeclr defines a declaration which produces argument based output of it's giving internals.

func Returns

func Returns(returns ...TypeDeclr) ReturnDeclr

Returns returns a new instance of a ReturnDeclr.

func (ReturnDeclr) WriteTo

func (f ReturnDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the function argument declaration.

type RuneASCIIDeclr

type RuneASCIIDeclr struct {
	Value rune `json:"value"`
}

RuneASCIIDeclr defines a declaration struct for representing a giving value.

func RuneASCII

func RuneASCII(rn rune) RuneASCIIDeclr

RuneASCII returns a new instance of a RuneASCIIDeclr.

func (RuneASCIIDeclr) String

func (n RuneASCIIDeclr) String() string

String returns the internal data associated with the structure.

func (RuneASCIIDeclr) WriteTo

func (n RuneASCIIDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type RuneDeclr

type RuneDeclr struct {
	Value rune `json:"value"`
}

RuneDeclr defines a declaration struct for representing a giving value.

func Rune

func Rune(rn rune) RuneDeclr

Rune returns a new instance of a RuneGraphicsDeclr.

func (RuneDeclr) String

func (n RuneDeclr) String() string

String returns the internal data associated with the structure.

func (RuneDeclr) WriteTo

func (n RuneDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type RuneGraphicsDeclr

type RuneGraphicsDeclr struct {
	Value rune `json:"value"`
}

RuneGraphicsDeclr defines a declaration struct for representing a giving value.

func RuneGraphics

func RuneGraphics(rn rune) RuneGraphicsDeclr

RuneGraphics returns a new instance of a RuneGraphicsDeclr.

func (RuneGraphicsDeclr) String

func (n RuneGraphicsDeclr) String() string

String returns the internal data associated with the structure.

func (RuneGraphicsDeclr) WriteTo

func (n RuneGraphicsDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type SingleBlockDeclr

type SingleBlockDeclr struct {
	Rune rune `json:"rune"`
}

SingleBlockDeclr defines a declaration which produces a block char which is written to a writer. eg. A BlockDeclr with Char '{'

Will produce '{' output.

func PrefixRune

func PrefixRune(start rune) SingleBlockDeclr

PrefixRune returns a new instance of a SingleBlockDeclr.

func SuffixRune

func SuffixRune(end rune) SingleBlockDeclr

SuffixRune returns a new instance of a SingleBlockDeclr.

func (SingleBlockDeclr) WriteTo

func (b SingleBlockDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type SingleByteBlockDeclr

type SingleByteBlockDeclr struct {
	Block []byte `json:"block"`
}

SingleByteBlockDeclr defines a declaration which produces a block byte slice which is written to a writer. declaration writer into it's block char. eg. A BlockDeclr with Char '{{'

Will produce '{{DataFROMWriter' output.

func PrefixByte

func PrefixByte(start []byte) SingleByteBlockDeclr

PrefixByte returns a new instance of a SingleByteBlockDeclr.

func SuffixByte

func SuffixByte(end []byte) SingleByteBlockDeclr

SuffixByte returns a new instance of a SingleByteBlockDeclr.

func (SingleByteBlockDeclr) WriteTo

func (b SingleByteBlockDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type SliceDeclr

type SliceDeclr struct {
	Type   TypeDeclr     `json:"type"`
	Values []io.WriterTo `json:"values"`
}

SliceDeclr defines a declaration struct for representing a go slice.

func Slice

func Slice(typeName string, elems ...io.WriterTo) SliceDeclr

Slice returns a new instance of a SliceDeclr.

func (SliceDeclr) WriteTo

func (t SliceDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type SliceTypeDeclr

type SliceTypeDeclr struct {
	Type TypeDeclr `json:"type"`
}

SliceTypeDeclr defines a declaration struct for representing a go slice.

func SliceType

func SliceType(ty string) SliceTypeDeclr

SliceType returns a new instance of a SliceTypeDeclr.

func (SliceTypeDeclr) WriteTo

func (t SliceTypeDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type SourceDeclr

type SourceDeclr struct {
	Template *tm.Template
	Binding  interface{}
}

SourceDeclr defines a declaration type which takes a giving source template and providing binding and will execute the template to generate it's output

func Source

func Source(tml *template.Template, binding interface{}) SourceDeclr

Source returns a new instance of a SourceDeclr.

func SourceWith

func SourceWith(tml *template.Template, dfns template.FuncMap, binding interface{}) SourceDeclr

SourceWith returns a new instance of a SourceDeclr.

func (SourceDeclr) WriteTo

func (src SourceDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type StringASCIIDeclr

type StringASCIIDeclr struct {
	Value string `json:"value"`
}

StringASCIIDeclr defines a declaration struct for representing a giving value.

func StringASCII

func StringASCII(rn string) StringASCIIDeclr

StringASCII returns a new instance of a StringASCIIDeclr.

func (StringASCIIDeclr) String

func (n StringASCIIDeclr) String() string

String returns the internal data associated with the structure.

func (StringASCIIDeclr) WriteTo

func (n StringASCIIDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type StringDeclr

type StringDeclr struct {
	Value string `json:"value"`
}

StringDeclr defines a declaration struct for representing a giving value.

func String

func String(rn string) StringDeclr

String returns a new instance of a StringDeclr.

func (StringDeclr) String

func (n StringDeclr) String() string

String returns the internal data associated with the structure.

func (StringDeclr) WriteTo

func (n StringDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type StructDeclr

type StructDeclr struct {
	Name        NameDeclr   `json:"name"`
	Type        TypeDeclr   `json:"type"`
	Comments    io.WriterTo `json:"comments"`
	Annotations io.WriterTo `json:"annotations"`
	Fields      WritersTo   `json:"fields"`
}

StructDeclr defines a declaration struct for representing a single comment.

func Interface

func Interface(name NameDeclr, comments io.WriterTo, annotations io.WriterTo, fields ...io.WriterTo) StructDeclr

Interface returns a new instance of a StructDeclr to generate a go struct.

func Struct

func Struct(name NameDeclr, comments io.WriterTo, annotations io.WriterTo, fields ...io.WriterTo) StructDeclr

Struct returns a new instance of a StructDeclr to generate a go struct.

func (StructDeclr) WriteTo

func (v StructDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type StructTypeDeclr

type StructTypeDeclr struct {
	Name NameDeclr `json:"name"`
	Type TypeDeclr `json:"typename"`
	Tags WritersTo `json:"tags"`
}

StructTypeDeclr defines a declaration which produces a variable declaration.

func Field

func Field(name NameDeclr, ntype TypeDeclr, tags ...io.WriterTo) StructTypeDeclr

Field returns a new instance of a StructTypeDeclr.

func (StructTypeDeclr) WriteTo

func (v StructTypeDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type SuffixDeclr

type SuffixDeclr struct {
	Suffix io.WriterTo `json:"-"`
	Value  io.WriterTo `json:"-"`
}

SuffixDeclr defines a declaration which produces a block with the provided prefix.

func Suffix

func Suffix(suffix, val io.WriterTo) SuffixDeclr

Suffix returns a new instance of a SuffixDelcr.

func (SuffixDeclr) WriteTo

func (b SuffixDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes the giving representation into the provided writer.

type SwitchDeclr

type SwitchDeclr struct {
	Condition io.WriterTo
	Cases     []CaseDeclr
	Default   DefaultCaseDeclr
}

SwitchDeclr defines a structure which generates switch declarations.

func Switch

func Switch(condition io.WriterTo, def DefaultCaseDeclr, cases ...CaseDeclr) SwitchDeclr

Switch returns a new instance of a SwitchDeclr.

func (SwitchDeclr) WriteTo

func (c SwitchDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the structure declaration.

type TagDeclr

type TagDeclr struct {
	Format string `json:"format"`
	Name   string `json:"name"`
}

TagDeclr defines a declaration for representing go type tags.

func Tag

func Tag(format string, name string) TagDeclr

Tag returns a new instance of a TagDeclr.

func (TagDeclr) WriteTo

func (v TagDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type TextBlockDeclr

type TextBlockDeclr struct {
	Text string `json:"text"`
}

TextBlockDeclr defines a declaration struct for representing a single comment.

func Text

func Text(txt string) TextBlockDeclr

Text returns a new instance of a TextDeclr.

func (TextBlockDeclr) String

func (n TextBlockDeclr) String() string

String returns the internal name associated with the NameDeclr.

func (TextBlockDeclr) WriteTo

func (n TextBlockDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type TextDeclr

type TextDeclr struct {
	Template string
	Name     string
	Binding  interface{}
	Funcs    tm.FuncMap
}

TextDeclr defines a declaration type which takes a giving source text and generate text.Template for it and providing binding and will execute the template to generate it's output

func SourceText

func SourceText(name string, tml string, binding interface{}) TextDeclr

SourceText returns a new instance of a TextDeclr.

func SourceTextWith

func SourceTextWith(name string, tml string, funcs template.FuncMap, binding interface{}) TextDeclr

SourceTextWith returns a new instance of a TextDeclr.

func (TextDeclr) WriteTo

func (tx TextDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the text declaration.

type TypeDeclr

type TypeDeclr struct {
	TypeName string `json:"typeName"`
}

TypeDeclr defines a declaration struct for representing a giving type.

func CustomMapType

func CustomMapType(mapdefType, mapType string, mapValue string) TypeDeclr

CustomMapType returns a combination of types that represent a map type.

func CustomMapValueVar

func CustomMapValueVar(mapdefType, mapType string, mapValue string) TypeDeclr

CustomMapValueVar returns a combination of types that represent a map type with its key and value.

func MapType

func MapType(maptype string, mapvalue string) TypeDeclr

MapType returns a combination of types that represent a map type.

func MapValueVar

func MapValueVar(mapType string, mapValue string) TypeDeclr

MapValueVar returns a combination of types that represent a map type.

func Type

func Type(name string) TypeDeclr

Type returns a new instance of a TypeDeclr.

func (TypeDeclr) String

func (t TypeDeclr) String() string

String returns the int64ernal name associated with the TypeDeclr.

func (TypeDeclr) WriteTo

func (t TypeDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type UInt32Declr

type UInt32Declr struct {
	Value uint32 `json:"value"`
}

UInt32Declr defines a declaration struct for representing a giving value.

func UInt32

func UInt32(rn uint32) UInt32Declr

UInt32 returns a new instance of a UInt32.

func (UInt32Declr) String

func (n UInt32Declr) String() string

String returns the internal data associated with the structure.

func (UInt32Declr) WriteTo

func (n UInt32Declr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type UInt64Declr

type UInt64Declr struct {
	Value uint64 `json:"value"`
}

UInt64Declr defines a declaration struct for representing a giving value.

func UInt64

func UInt64(rn uint64) UInt64Declr

UInt64 returns a new instance of a UInt64.

func (UInt64Declr) String

func (n UInt64Declr) String() string

String returns the internal data associated with the structure.

func (UInt64Declr) WriteTo

func (n UInt64Declr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type UIntBaseDeclr

type UIntBaseDeclr struct {
	Value uint64 `json:"value"`
	Base  int    `json:"base"`
}

UIntBaseDeclr defines a declaration struct for representing a giving value.

func UIntBase

func UIntBase(rn uint64, base int) UIntBaseDeclr

UIntBase returns a new instance of a UIntBaseDeclr.

func (UIntBaseDeclr) String

func (n UIntBaseDeclr) String() string

String returns the internal data associated with the structure.

func (UIntBaseDeclr) WriteTo

func (n UIntBaseDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type ValueAssignmentDeclr

type ValueAssignmentDeclr struct {
	Name  NameDeclr   `json:"name"`
	Value io.WriterTo `json:"value"`
}

ValueAssignmentDeclr defines a declaration which produces a variable declaration.

func AssignValue

func AssignValue(name NameDeclr, value io.WriterTo) ValueAssignmentDeclr

AssignValue returns a new instance of a ValueAssignmentDeclr.

func MapAssignValue

func MapAssignValue(mapname string, key string, value string) ValueAssignmentDeclr

MapAssignValue returns a new instance of a ValueAssignmentDeclr.

func (ValueAssignmentDeclr) WriteTo

func (v ValueAssignmentDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type ValueDeclr

type ValueDeclr struct {
	Value          interface{}              `json:"value"`
	ValueConverter func(interface{}) string `json:"-"`
}

ValueDeclr defines a declaration struct for representing a giving value.

func Value

func Value(rn interface{}, converter func(interface{}) string) ValueDeclr

Value returns a new instance of a ValueDeclr.

func (ValueDeclr) String

func (n ValueDeclr) String() string

String returns the internal data associated with the structure.

func (ValueDeclr) WriteTo

func (n ValueDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type VariableAssignmentDeclr

type VariableAssignmentDeclr struct {
	Name  NameDeclr   `json:"name"`
	Value io.WriterTo `json:"value"`
}

VariableAssignmentDeclr defines a declaration which produces a variable declaration.

func AssignVar

func AssignVar(name NameDeclr, value io.WriterTo) VariableAssignmentDeclr

AssignVar returns a new instance of a VariableAssignmentDeclr.

func (VariableAssignmentDeclr) WriteTo

func (v VariableAssignmentDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type VariableNameDeclr

type VariableNameDeclr struct {
	Name NameDeclr `json:"name"`
}

VariableNameDeclr defines a declaration which produces a variable declaration.

func VarName

func VarName(name NameDeclr) VariableNameDeclr

VarName returns a new instance of a VariableNameDeclr.

func (VariableNameDeclr) WriteTo

func (v VariableNameDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type VariableShortAssignmentDeclr

type VariableShortAssignmentDeclr struct {
	Name  NameDeclr   `json:"name"`
	Value io.WriterTo `json:"value"`
}

VariableShortAssignmentDeclr defines a declaration which produces a variable declaration.

func AssignMap

func AssignMap(name string, maptype string, mapvalue string) VariableShortAssignmentDeclr

AssignMap returns a combination of types that represent a map type.

func Var

Var returns a new instance of a VariableShortAssignmentDeclr.

func (VariableShortAssignmentDeclr) WriteTo

WriteTo writes to the provided writer the variable declaration.

type VariableTypeDeclr

type VariableTypeDeclr struct {
	Name NameDeclr `json:"name"`
	Type TypeDeclr `json:"typename"`
}

VariableTypeDeclr defines a declaration which produces a variable declaration.

func MapVar

func MapVar(name string, maptype string, mapvalue string) VariableTypeDeclr

MapVar returns a combination of types that represent a map type.

func VarType

func VarType(name NameDeclr, ntype TypeDeclr) VariableTypeDeclr

VarType returns a new instance of a VariableTypeDeclr.

func (VariableTypeDeclr) WriteTo

func (v VariableTypeDeclr) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

type WriteCounter

type WriteCounter struct {
	io.Writer
	// contains filtered or unexported fields
}

WriteCounter defines a struct which collects write counts of a giving io.Writer

func NewWriteCounter

func NewWriteCounter(w io.Writer) *WriteCounter

NewWriteCounter returns a new instance of the WriteCounter.

func (*WriteCounter) Write

func (w *WriteCounter) Write(data []byte) (int, error)

Write calls the internal io.Writer.Write method and adds up the write counts.

func (*WriteCounter) Written

func (w *WriteCounter) Written() int64

Written returns the total number of data writer to the underline writer.

type WriteDirective

type WriteDirective struct {
	Writer       io.WriterTo `ast:"-,!optional"`       // WriteTo which contains the complete content of the file to be written to.
	Dir          string      `ast:"dir,optional"`      // Relative dir path written into it if not existing.
	FileName     string      `ast:"filename,optional"` // alternative fileName to use for new file.
	DontOverride bool        `ast:"dont_override,optional"`
	Before       func() error
	After        func() error
}

WriteDirective defines a struct which contains giving directives as to the file and the relative path within which it should be written to. Include are tags which give meta description of the optionality of each field.

type WriterToMap

type WriterToMap interface {
	Map(...io.WriterTo) io.WriterTo
}

WriterToMap defines a int64erface which maps giving declaration values int64o appropriate form for final output. It allows us create custom wrappers to define specific output style for a giving set of declarations.

type WritersTo

type WritersTo []io.WriterTo

WritersTo defines the body contents of a giving declaration/structure.

func (WritersTo) Map

func (d WritersTo) Map(mp WriterToMap) io.WriterTo

Map applies a giving declaration mapper to the underlying io.Readers of the io.WriterTo.

func (WritersTo) WriteTo

func (d WritersTo) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the provided writer the variable declaration.

Directories

Path Synopsis
osconv
Package osconv defines a function which runs through a giving directory and returns a Filesystem in return.
Package osconv defines a function which runs through a giving directory and returns a Filesystem in return.

Jump to

Keyboard shortcuts

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