decorator

package
v0.0.5-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package decorator provides functionality for parsing a decorater yaml and returns the result

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncorrectDecoratorType    error = fmt.Errorf("incorrect dececorator type")
	ErrParamNotFoundInFunc       error = fmt.Errorf("param name not found")
	ErrReceiverNotFoundInFunc    error = fmt.Errorf("receiver not found")
	ErrNoInputParamsExpected     error = fmt.Errorf("expected no input parameters")
	ErrExpectedOneRetrunVal      error = fmt.Errorf("expected only one return value")
	ErrDecoratorFuncNameNotFound error = fmt.Errorf("decorator func name not found")
	ErrMissingFileName           error = fmt.Errorf("missing file name")
)

error definitions

Functions

func GetDecoratorFile

func GetDecoratorFile(dir, file string) (*ast.File, error)

GetDecoratorFile retrieve file with decorator spec

func ParseFile

func ParseFile(filePath string) (*ast.File, error)

ParseFile creates ast file from path

func ValidateParamVals

func ValidateParamVals(f *ast.File, funcName, paramName string, decoType ast.Expr) error

ValidateParamVals validate file with given decorator type

func ValidateReceiverVals

func ValidateReceiverVals(f *ast.File, funcName string, decoType ast.Expr) error

ValidateReceiverVals validates the type of a custom receiver value

func ValidateRes

func ValidateRes(res *Deco, dir string) error

ValidateRes validate the resulting decorator for given dir

Types

type CustomVal

type CustomVal struct {
	Type ast.Expr
	Call *ast.CallExpr
}

CustomVal value for a given parameter or receiver consists of a type and call expression

func FindCustomVal

func FindCustomVal(f *ast.File, funcName string) (*CustomVal, error)

FindCustomVal find parameter value for given spec

type Deco

type Deco struct {
	Files map[string]*File
}

Deco result of a decorator file

func ConvertSpec

func ConvertSpec(n *ast.File, spec *Spec) (*Deco, error)

ConvertSpec convert spec to decorator result

func GetDecorators

func GetDecorators(dir string) (*Deco, error)

GetDecorators retrieves decorators if specified in given file

func YamlToSpec

func YamlToSpec(dir string) (*Deco, error)

YamlToSpec converts yaml file to result

func (*Deco) GetReceiverVal

func (d *Deco) GetReceiverVal(fileName, funcName string) []*CustomVal

GetReceiverVal retrieves receiver values for given file and func

func (*Deco) GetVal

func (d *Deco) GetVal(fileName, funcName, paramName string) []*CustomVal

GetVal retrieves a value

func (*Deco) HasReceiverVal

func (d *Deco) HasReceiverVal(fileName, funcName string) bool

HasReceiverVal checks if a receiver val is specified

func (*Deco) HasVal

func (d *Deco) HasVal(fileName, funcName, paramName string) bool

HasVal check if decorator has value for given file, func and param name

func (*Deco) ShouldIgnoreFile

func (d *Deco) ShouldIgnoreFile(fileName string) bool

ShouldIgnoreFile checks if a file should be ignored

func (*Deco) ShouldIgnoreFunc

func (d *Deco) ShouldIgnoreFunc(fileName, funcName string) bool

ShouldIgnoreFunc checks if a function should be ignored

type File

type File struct {
	Ignore bool
	Funcs  map[string]*Func
}

File file decorator

type FileSpec

type FileSpec struct {
	Name   string     `yaml:"name"`
	Ignore bool       `yaml:"ignore"`
	Funcs  []FuncSpec `yaml:"funcs"`
}

FileSpec file spec of decorator file

type Func

type Func struct {
	Ignore         bool
	ReceiverValues []*CustomVal
	Params         map[string]*Param
}

Func func decorator

type FuncSpec

type FuncSpec struct {
	Name           string      `yaml:"name"`
	Ignore         bool        `yaml:"ignore"`
	ReceiverValues []string    `yaml:"receiver_values"`
	Params         []ParamSpec `yaml:"params"`
}

FuncSpec function spec of decorator file

type Param

type Param struct {
	Values []*CustomVal
}

Param param decorator

type ParamSpec

type ParamSpec struct {
	Name   string   `yaml:"name"`
	Values []string `yaml:"values"`
}

ParamSpec param spec of decorator file

type Spec

type Spec struct {
	CustomVals string     `yaml:"custom_vals"`
	Files      []FileSpec `yaml:"files"`
}

Spec spec of decorator file

func ParseYaml

func ParseYaml(dir string) (*Spec, error)

ParseYaml parses a yaml for given file

Jump to

Keyboard shortcuts

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