lg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultParseMode = parser.AllErrors | parser.ParseComments

Variables

This section is empty.

Functions

func FnName

func FnName(fn any) string

func Funcs

func Funcs() template.FuncMap

func GenerateLayer

func GenerateLayer(tmpl string, funcs template.FuncMap, outputFile string, data any, reformat bool) error

func IsError

func IsError(Type string) bool

func IsPrivate

func IsPrivate(val string) bool

IsPrivate returns ture if the value is a private value. As you know, a type, field, interface,... is private in go if it's first letter is a lowercase.

func IsSamePackage

func IsSamePackage(pkg *Package, target *Package) bool

func Lookup

func Lookup(tag reflect.StructTag, keys ...string) (string, bool)

func ResultVar

func ResultVar(index int) string

func SetPackageOnType

func SetPackageOnType(pkg string, t string) string

SetPackageOnType sets the package in the type. e.g., hexa, Health => hexa.Health e.g., hexa, []*Health => []*hexa.Health

func UseTypeInPackage

func UseTypeInPackage(from *Package, t string) string

UseTypeInPackage returns the type that we can use in another package. e.g., if we provide Health from the hexa package. it returns hexa.Health.

Types

type Annotation

type Annotation struct {
	Name string
	Tag  reflect.StructTag
}

Annotation is a type of comment on any goalng ndoe (struct, method, field,...) that has following format: @annotationName `tagField:"tag val" anotherField:"another val"` e.g., @tx `retryCount:"4"`

type Annotations

type Annotations []Annotation

func (Annotations) Lookup

func (a Annotations) Lookup(name string) *Annotation

type EmbeddedField

type EmbeddedField struct {
	IsResolved  bool // When we add all fields of the embedded type to its parent type, it's resolved.
	Doc         string
	Annotations Annotations
	Type        string
	Tag         reflect.StructTag
}

func UseEmbeddedFieldsInPackage

func UseEmbeddedFieldsInPackage(from *Package, fields []*EmbeddedField) []*EmbeddedField

UseEmbeddedFieldsInPackage updates the embedded fields to be able to use in another package.

type EmbeddedResolveFilter

type EmbeddedResolveFilter func(e *EmbeddedField) bool

type EmbeddedResolver

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

func NewEmbeddedResolver

func NewEmbeddedResolver(packages ...*Package) *EmbeddedResolver

func NewEmbeddedResolverWithOpts

func NewEmbeddedResolverWithOpts(packages []*Package, filter EmbeddedResolveFilter) *EmbeddedResolver

func (*EmbeddedResolver) Resolve

func (r *EmbeddedResolver) Resolve() error

type Field

type Field struct {
	Doc         string
	Annotations Annotations
	Name        string
	Type        string
	Tag         reflect.StructTag
}

func UseFieldsInPackage

func UseFieldsInPackage(from *Package, fields []*Field) []*Field

UseFieldsInPackage updates fields to be able to use in the another package. e.g., when we want to use ``` type Hi struct{h Health} ``` in another package, it should be: ``` type Hi struct{h hexa.Health} ```

type File

type File struct {
	ImportMap map[string]string // map's key is the imported package's name or its alias, value is the package's path. e.g., hexa -> github.com/kamva/hexa

	PackageName string // The package's name. e.g., hexa
	Imports     []*Import

	Interfaces []*Interface // map's key is the interface's name.
	Structs    []*Struct    // map's key is the struct name.
}

func NewFile

func NewFile(f *ast.File) *File

func NewFileByName

func NewFileByName(filename string, mode parser.Mode) (*File, error)

func (*File) FindInterface

func (f *File) FindInterface(name string) *Interface

func (*File) FindStruct

func (f *File) FindStruct(name string) *Struct

type Import

type Import struct {
	Name string // For regular imports this value is empty. For alias imports it's the alias.
	Path string
}

type Interface

type Interface struct {
	Doc         string
	Annotations Annotations
	Name        string
	Embedded    []*EmbeddedField
	Methods     []*Method
}

func UseInterfaceInPackage

func UseInterfaceInPackage(from *Package, iface *Interface) *Interface

UseInterfaceInPackage updates the interface to be able to use it in another package.

func (*Interface) MethodByName

func (i *Interface) MethodByName(name string) *Method

type Method

type Method struct {
	Doc         string
	Annotations Annotations
	Name        string
	Params      []*MethodParam
	Results     []*MethodResult
}

func UseMethodsInPackage

func UseMethodsInPackage(from *Package, methods []*Method) []*Method

UseMethodsInPackage updates the method's params and results to use in another package. e.g., when want to use checkHealth(h Health) to another package, it should be checkHealth(h hexa.Health).

type MethodParam

type MethodParam struct {
	Name string
	Type string
}

type MethodResult

type MethodResult = MethodParam

type Package

type Package struct {
	Name  string  // e.g., hexa
	Path  string  // e.g., github.com/kamva/hexa
	Files []*File // The golang files
}

func NewPackage

func NewPackage(pkgPath string, files []*File) *Package

func NewPackageFromAstPackage

func NewPackageFromAstPackage(pkgPath string, astPkg *ast.Package) *Package

func NewPackageFromFilenames

func NewPackageFromFilenames(pkgPath string, filenames ...string) (*Package, error)

func NewPackageFromFilenamesWithOpts

func NewPackageFromFilenamesWithOpts(pkgPath string, mode parser.Mode, filenames ...string) (*Package, error)

func PackagesFromDirs

func PackagesFromDirs(pkgDirs map[string]string) ([]*Package, error)

PackagesFromDirs returns list of packages. pkgDirs params is a map from package's path to the dir path.

func PackagesFromDirsWithOpts

func PackagesFromDirsWithOpts(pkgDirs map[string]string, filter func(fs.FileInfo) bool, mode parser.Mode) ([]*Package, error)

func SinglePackageFromDir

func SinglePackageFromDir(pkgPath string, dir string) (*Package, error)

func SinglePackageFromDirWithOpts

func SinglePackageFromDirWithOpts(pkgPath string, dir string, filter func(fs.FileInfo) bool, mode parser.Mode) (*Package, error)

func (*Package) FindInterface

func (p *Package) FindInterface(name string) (*File, *Interface)

func (*Package) FindStruct

func (p *Package) FindStruct(name string) (*File, *Struct)

type Struct

type Struct struct {
	Doc         string
	Annotations Annotations
	Name        string
	Embedded    []*EmbeddedField
	Fields      []*Field
}

func UseStructInPackage

func UseStructInPackage(from *Package, strct *Struct) *Struct

UseStructInPackage updates the struct to be able to use it in another package.

type TemplateData

type TemplateData struct {
	Package   string
	Name      string // struct name for the implementation of our interface
	Interface *Interface
}

Jump to

Keyboard shortcuts

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