printer

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package printer conatains code generator using analyzer's models.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid config")

ErrInvalidConfig returns when you create printer with invalid config params.

Functions

This section is empty.

Types

type Convertor

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

Convertor converts models to code.

func NewConvertor

func NewConvertor() *Convertor

NewConvertor returns a new converter based on a pkg name of the generated file.

func (*Convertor) ArgumentString

func (c *Convertor) ArgumentString(a *model.Argument) string

ArgumentString converts method's argument in string.

func (*Convertor) ArgumentTypeConvertString

func (c *Convertor) ArgumentTypeConvertString(a *model.Argument) string

ArgumentTypeConvertString converts method's argument type in string to pass it to the converting code. For example *pkg.Type -> v.(*pkg.Type) or ...*pkg.Type -> v.([]*pkg.Type).

func (*Convertor) ArgumentTypeString

func (c *Convertor) ArgumentTypeString(a *model.Argument) string

ArgumentTypeString converts method's argument type in string.

func (*Convertor) GetPkgPathName

func (c *Convertor) GetPkgPathName(pkgPath string) string

GetPkgPathName returns name of the path pkg for types.

func (*Convertor) GetQualifiedType

func (c *Convertor) GetQualifiedType(pkgPath, typeName string) string

GetQualifiedType returns type name with package prefix.

func (*Convertor) GetZeroValue

func (c *Convertor) GetZeroValue(arg *model.Argument) string

GetZeroValue returns zero value of the argument.

func (*Convertor) MethodTuplesString

func (c *Convertor) MethodTuplesString(m *model.Method) string

MethodTuplesString returns tuples string of the method or func.

func (*Convertor) PrintFileImports

func (c *Convertor) PrintFileImports() string

PrintFileImports prints all imports collected in usedImports. Prints just rows with import and alias.

func (*Convertor) SetFileParams

func (c *Convertor) SetFileParams(currentPkg string)

SetFileParams resets used imports of the file and set new package name.

type Printer

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

Printer creates new genereted files with interface implementers.

func New

func New(log *zerolog.Logger, conf *config.Print, stdout io.Writer, version string) (*Printer, error)

New validate config and created new code printer.

func (*Printer) GetFileName

func (p *Printer) GetFileName(ifaceName string) string

GetFileName returns file name of based on interface name and config.

func (*Printer) GetFilePath

func (p *Printer) GetFilePath(iface *model.Interface) string

GetFilePath returns full path to the new file based on config and interface location.

func (*Printer) Run

func (p *Printer) Run(ctx context.Context, ifaces []*model.Interface) error

Run runs new code generator. Generates code of the interface implementers and saves it to files.

Jump to

Keyboard shortcuts

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