generator

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EndOfLine is simply the end of line character
	EndOfLine = "\n"
	// Intend contains the tab char
	Intend = "\t"
	// Quote contains a single double quote
	Quote = string('"')
)

Functions

This section is empty.

Types

type FileGoGenerator

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

FileGoGenerator is a basic implementation of the GoGenerator that is capable of creating a go file

func NewFileGoGenerator

func NewFileGoGenerator(packageName string) *FileGoGenerator

NewFileGoGenerator returns a new instance of the FileGoGenerator

func (*FileGoGenerator) Flush

func (f *FileGoGenerator) Flush(writer io.Writer)

Flush flushes the content to a writer

func (*FileGoGenerator) Import

func (f *FileGoGenerator) Import(importName string) GoGenerator

Import adds a new import to the generator

func (*FileGoGenerator) Method

func (f *FileGoGenerator) Method(name string, consumer func(method MethodGenerator)) GoGenerator

Method adds a new method to the generator

func (*FileGoGenerator) Struct

func (f *FileGoGenerator) Struct(name string, consumer func(s StructGenerator)) GoGenerator

Struct adds a new struct to the generator

type GoGenerator

type GoGenerator interface {
	Import(importName string) GoGenerator
	Method(name string, consumer func(m MethodGenerator)) GoGenerator
	Struct(name string, consumer func(s StructGenerator)) GoGenerator
	Flush(writer io.Writer)
}

GoGenerator is an interface that is capable of generating go files

Package sets the package name of the generated file

Import adds an import to the file

Method adds a new method with a method body to the go generator

Struct adds a new struct to the generator

Flush flushes the generated content into the writer

type MethodGenerator

type MethodGenerator interface {
	Parameters(parameters ...string) MethodGenerator
	Receiver(r string) MethodGenerator
	ReturnTypes(returnTypes ...string) MethodGenerator
	Body(body ...string) MethodGenerator
}

MethodGenerator defines an object that can generate a go method

Parameters sets the parameters

Receiver adds a receiver string

ReturnTypes adds the return types

Body adds the method body

type SimpleMethodGenerator

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

SimpleMethodGenerator is a basic implementation of the MethodGenerator interface

func (*SimpleMethodGenerator) Body

func (m *SimpleMethodGenerator) Body(body ...string) MethodGenerator

Body sets the body of the generated method

func (*SimpleMethodGenerator) Flush

func (m *SimpleMethodGenerator) Flush(writer io.Writer)

Flush flushes the content of the generator to a writer instance

func (*SimpleMethodGenerator) Parameters

func (m *SimpleMethodGenerator) Parameters(parameters ...string) MethodGenerator

Parameters sets the parameters of the generated method

func (*SimpleMethodGenerator) Receiver

Receiver sets the receiver type of the generated method

func (*SimpleMethodGenerator) ReturnTypes

func (m *SimpleMethodGenerator) ReturnTypes(returnTypes ...string) MethodGenerator

ReturnTypes sets the return-types of the generated method

type SimpleStructGenerator

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

SimpleStructGenerator is a simple implementation of the StructGenerator interface

func (*SimpleStructGenerator) Field

func (s *SimpleStructGenerator) Field(name string, fieldType string) StructGenerator

Field adds a new field to the struct generator

func (*SimpleStructGenerator) Flush

func (s *SimpleStructGenerator) Flush(writer io.Writer)

Flush flushes the content of the struct

type StructGenerator

type StructGenerator interface {
	Field(name string, fieldType string) StructGenerator
}

StructGenerator is a generator for struct inside a go file

Flush flushes the generator to the writer

Field adds a new field to the struct

Jump to

Keyboard shortcuts

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