generator

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.4.0

func Contains[T comparable](arr []T, a T) bool

func JoinAround added in v0.3.0

func JoinAround(strs []string, left, right, separator string) string

func MergeMaps added in v0.2.0

func MergeMaps(m, m2 map[string]string)

func Register

func Register(gen Plugin)

func ScanAndGenerateFile added in v0.5.0

func ScanAndGenerateFile(workDir, fullFileName string)

func ScanCurrentDir

func ScanCurrentDir(options ...ScanOption)

func ScanCurrentDirAndSubDirs

func ScanCurrentDirAndSubDirs(options ...ScanOption)

func ScanDir added in v0.5.0

func ScanDir(dir string, options ...ScanOption)

func ScanDirAndSubDirs added in v0.5.0

func ScanDirAndSubDirs(dir string, options ...ScanOption)

func SetGenSuffix added in v0.5.0

func SetGenSuffix(s string)

func UncapFirst

func UncapFirst(s string) string

func UncapFirstSingle added in v0.2.0

func UncapFirstSingle(s string) string

func Unregister added in v0.5.0

func Unregister(gen Plugin)

func UnregisterAll added in v0.5.0

func UnregisterAll()

func Zero added in v0.2.2

func Zero(typ string) (string, bool)

Types

type Array

type Array struct {
	Kinder
}

func (Array) String

func (a Array) String() string

func (Array) Zero added in v0.3.0

func (a Array) Zero() string

func (Array) ZeroCondition added in v0.2.0

func (Array) ZeroCondition(field string) string

type Basic

type Basic struct {
	Pck  string
	Type string
}

func (Basic) Name

func (b Basic) Name() string

func (Basic) String

func (b Basic) String() string

func (Basic) Zero added in v0.3.0

func (b Basic) Zero() string

func (Basic) ZeroCondition added in v0.2.0

func (b Basic) ZeroCondition(field string) string

type Field

type Field struct {
	Tags
	Name string
	Kind Kinder
}

func (Field) IsContext added in v0.3.0

func (f Field) IsContext() bool

func (Field) IsError added in v0.3.0

func (f Field) IsError() bool

func (Field) IsFunc added in v0.5.0

func (f Field) IsFunc() bool

func (Field) IsNested added in v0.2.0

func (f Field) IsNested() bool

func (Field) IsPrimitive added in v0.2.2

func (f Field) IsPrimitive() bool

func (Field) NameForField added in v0.2.0

func (f Field) NameForField() string

func (Field) NameOrKindName

func (f Field) NameOrKindName() string

func (Field) String

func (f Field) String() string

type Interface added in v0.2.2

type Interface struct {
	Tags
	Name    string
	Methods []Method
	Package string
	Dir     []string
}

func (*Interface) AddMethod added in v0.4.0

func (s *Interface) AddMethod(m Method)

func (*Interface) FindMethod added in v0.4.0

func (s *Interface) FindMethod(name string) (Method, bool)

func (*Interface) GetDir added in v0.6.0

func (s *Interface) GetDir() []string

func (*Interface) GetFields added in v0.4.0

func (s *Interface) GetFields() []Field

func (*Interface) GetMethods added in v0.4.0

func (s *Interface) GetMethods() []Method

func (*Interface) GetName added in v0.4.0

func (s *Interface) GetName() string

func (*Interface) GetPackage added in v0.6.0

func (s *Interface) GetPackage() string

func (*Interface) GetTags added in v0.4.0

func (s *Interface) GetTags() Tags

func (*Interface) Type added in v0.2.2

func (s *Interface) Type() MapperType

type InterfaceVar added in v0.4.0

type InterfaceVar struct {
	Tags
	Pck     string
	Type    string
	Methods []Method
}

func (*InterfaceVar) Name added in v0.4.0

func (b *InterfaceVar) Name() string

func (*InterfaceVar) String added in v0.4.0

func (b *InterfaceVar) String() string

func (*InterfaceVar) Zero added in v0.4.0

func (b *InterfaceVar) Zero() string

func (*InterfaceVar) ZeroCondition added in v0.4.0

func (b *InterfaceVar) ZeroCondition(field string) string

type Kinder

type Kinder interface {
	Name() string
	String() string
	ZeroCondition(string) string
	Zero() string
}

type Map

type Map struct {
	Key Kinder
	Val Kinder
}

func (Map) Name

func (m Map) Name() string

func (Map) String

func (m Map) String() string

func (Map) Zero added in v0.3.0

func (m Map) Zero() string

func (Map) ZeroCondition added in v0.2.0

func (Map) ZeroCondition(field string) string

type Mapper added in v0.4.0

type Mapper interface {
	Type() MapperType
	GetTags() Tags
	GetName() string
	GetFields() []Field
	GetMethods() []Method
	AddMethod(Method)
	FindMethod(name string) (Method, bool)
	GetPackage() string
	GetDir() []string
}

type MapperType added in v0.4.0

type MapperType string
const (
	StructMapper    MapperType = "struct"
	InterfaceMapper MapperType = "interface"
)

type Method

type Method struct {
	Tags
	FuncName string
	Args     []Field
	Results  []Field
}

func (*Method) Call added in v0.3.0

func (m *Method) Call(withName bool) string

func (*Method) ContextArgName added in v0.3.0

func (m *Method) ContextArgName() string

func (*Method) HasResults added in v0.3.0

func (m *Method) HasResults() bool

func (*Method) IsExported added in v0.4.0

func (m *Method) IsExported() bool

func (*Method) Name

func (m *Method) Name() string

func (*Method) NamedReturns added in v0.6.0

func (m *Method) NamedReturns() string

func (*Method) Parameters added in v0.3.0

func (m *Method) Parameters(onlyName bool) string

func (*Method) ReturnAssignments added in v0.6.0

func (m *Method) ReturnAssignments() (all string, errVar string)

HasErrorReturn returns if it has an error return and its position

func (*Method) ReturnZerosWithError added in v0.3.0

func (m *Method) ReturnZerosWithError(errVar string) string

func (*Method) Returns added in v0.3.0

func (m *Method) Returns() string

func (*Method) Signature added in v0.3.0

func (m *Method) Signature(withName bool) string

func (*Method) String

func (m *Method) String() string

func (Method) Zero added in v0.3.0

func (Method) Zero() string

func (Method) ZeroCondition added in v0.2.0

func (Method) ZeroCondition(field string) string

type Parser

type Parser struct {
	Scribler

	Imports map[string]string
	Mappers []Mapper
	// contains filtered or unexported fields
}

func InspectGoFile

func InspectGoFile(relativePathToRoot []string, parsedFile *ast.File) *Parser

func NewParser

func NewParser(parsedFile *ast.File) *Parser

func (*Parser) GenerateCode

func (p *Parser) GenerateCode(filename string) ([]byte, error)

type Plugin

type Plugin interface {
	Accepts() []MapperType
	Imports(Mapper) map[string]string
	GenerateBody(Mapper) error
	Name() string
	Flush() []byte
}

type Pointer

type Pointer struct {
	Kinder
}

func (Pointer) String

func (p Pointer) String() string

func (Pointer) Zero added in v0.3.0

func (p Pointer) Zero() string

func (Pointer) ZeroCondition added in v0.2.2

func (Pointer) ZeroCondition(field string) string

type ScanOption added in v0.5.0

type ScanOption func(*ScanOptions)

func WithDirOut added in v0.5.0

func WithDirOut(dirOut string) ScanOption

type ScanOptions added in v0.5.0

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

type Scribler

type Scribler struct {
	Header bytes.Buffer
	Body   bytes.Buffer
}

func (*Scribler) BPrint added in v0.3.0

func (s *Scribler) BPrint(args ...interface{})

func (*Scribler) BPrintf added in v0.2.0

func (s *Scribler) BPrintf(format string, args ...interface{})

func (*Scribler) BPrintln added in v0.3.0

func (s *Scribler) BPrintln(args ...interface{})

func (*Scribler) Flush

func (s *Scribler) Flush() []byte

func (*Scribler) HPrint added in v0.3.0

func (s *Scribler) HPrint(args ...interface{})

func (*Scribler) HPrintf

func (s *Scribler) HPrintf(format string, args ...interface{})

func (*Scribler) HPrintln added in v0.3.0

func (s *Scribler) HPrintln(args ...interface{})

func (Scribler) Len

func (s Scribler) Len() int

func (Scribler) String

func (s Scribler) String() string

type Struct

type Struct struct {
	Tags
	Name    string
	Fields  []Field
	Methods []Method
	Package string
	Dir     []string
}

func (*Struct) AddMethod added in v0.4.0

func (s *Struct) AddMethod(m Method)

func (*Struct) FindMethod

func (s *Struct) FindMethod(name string) (Method, bool)

func (*Struct) GetDir added in v0.6.0

func (s *Struct) GetDir() []string

func (*Struct) GetFields added in v0.4.0

func (s *Struct) GetFields() []Field

func (*Struct) GetMethods added in v0.4.0

func (s *Struct) GetMethods() []Method

func (*Struct) GetName added in v0.4.0

func (s *Struct) GetName() string

func (*Struct) GetPackage added in v0.6.0

func (s *Struct) GetPackage() string

func (*Struct) GetTags added in v0.4.0

func (s *Struct) GetTags() Tags

func (*Struct) Type added in v0.4.0

func (s *Struct) Type() MapperType

type Tag

type Tag struct {
	Name string
	Args string
}

func (Tag) Unmarshal

func (t Tag) Unmarshal(v interface{}) error

type Tags

type Tags []Tag

func (Tags) Filter added in v0.3.0

func (t Tags) Filter(filter ...string) []Tag

func (Tags) FindTag

func (t Tags) FindTag(tag string) (Tag, bool)

func (Tags) HasTag

func (t Tags) HasTag(tag string) bool

type TypeEnum

type TypeEnum int

Jump to

Keyboard shortcuts

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