proxygen

package module
v0.0.0-...-2596838 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 12 Imported by: 0

README

proxygen

Tracing Generator for that comply proxy design pattern

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixImports

func FixImports(filename string) error

FixImports will fix and formattion any missing error in the generated code

func Generate

func Generate(filename, interfaceNames, outputDir, packageName string) error

This is to used by cmd or main pacage

func GenerateTracerFileName

func GenerateTracerFileName(filename string) string

Types

type Collector

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

Collector is the first entry door of this logic. To start generated code we need to instantiate this collector with NewCollector. Then fill the filename that this Collector need to read

func NewCollector

func NewCollector() *Collector

NewCollector will return new Collector

func (*Collector) FindInterface

func (c *Collector) FindInterface(name string) (*InterfaceType, error)

FindInterface will return InterfaceType that can be transformed by transformer

func (*Collector) Load

func (c *Collector) Load(filename string) error

Load will make the program read the file, then get ast from it

type Func

type Func struct {
	Name     string
	Receiver Var
	Params   MultiVar
	Return   MultiVar
	BaseType string
}

Func is struct that used to store data that can be used into Generate function.

func (*Func) FixEmptyParams

func (f *Func) FixEmptyParams()

FixEmptyParams will set empty params names and set it with arg0 arg1 and so on..

func (Func) FuncText

func (f Func) FuncText() FuncText

FuncText generate FuncText that can be used in template

type FuncText

type FuncText struct {
	Func
	ReceiverText string
	ParamsText   string
	ReturnText   string
	ParamsNames  string
}

FuncText is struct that will be used as input to be used in func template and struct template

type Generator

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

Generator will generate code with input Proxy

func NewGenerator

func NewGenerator() *Generator

NewGenerator will instatiate Generator that have FuncGenerator and StructGenerator

func (*Generator) Generate

func (g *Generator) Generate(out io.Writer, data Proxy, pgkName string) error

Generate will generate proxy struct and all its funs into out (io.Writer) this function doesnt generate package name at first line. If you need to also generate package you can use GenerateAll

func (*Generator) GenerateAll

func (g *Generator) GenerateAll(out io.Writer, data []Proxy, pkgName string) error

GenerateAll with generat all proxies from Proxies into out (io.Writer)

type InterfaceType

type InterfaceType struct {
	Name        string
	PackageName string
	Ast         *ast.InterfaceType
}

type MultiVar

type MultiVar []Var

MultiVar is list of Var. Ussually used in Params and Returns And ussually used in function body

func (MultiVar) Names

func (m MultiVar) Names() string

Names will return string that can be used in calling based function

func (MultiVar) Text

func (m MultiVar) Text() string

Text will return string that can be used in Params, Return

type Proxy

type Proxy struct {
	PackageName string
	BaseType    string
	Type        string
	Funcs       []Func
}

Proxy is struct that store data that can be used to generate Struct and its function

func (*Proxy) SetBaseType

func (p *Proxy) SetBaseType(baseType string)

SetBaseType will set it BaseType and its functions BaseType

func (*Proxy) SetRecieverTypeSuffix

func (p *Proxy) SetRecieverTypeSuffix(suffix string)

SetRecieverTypeSuffix will set receiver for functions and struct

type StructMethods

type StructMethods struct {
	StructName  string
	PackageName string
	Ast         []*ast.FuncDecl
}

func FindStructMethods

func FindStructMethods(path string, structName string) (StructMethods, error)

type Var

type Var struct {
	Name string
	Type string
}

Var is struct to store variable name and it's type it can be used as Receiver, Params, Return or used in Body. It doesn't need to have Name. For examples in Return ussually we used Something like Var{Name:"", Type:"entity.Result"}, Var{Name:"", Type:"error"}

func (Var) Text

func (v Var) Text() string

Text will return string that can be used in Params, Return and Receiver

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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