Documentation ¶
Index ¶
- Constants
- func FnName(fn any) string
- func Funcs() template.FuncMap
- func GenerateLayer(tmpl string, funcs template.FuncMap, outputFile string, data any, ...) error
- func IsError(Type string) bool
- func IsPrivate(val string) bool
- func IsSamePackage(pkg *Package, target *Package) bool
- func Lookup(tag reflect.StructTag, keys ...string) (string, bool)
- func ResultVar(index int) string
- func SetPackageOnType(pkg string, t string) string
- func UseTypeInPackage(from *Package, t string) string
- type Annotation
- type Annotations
- type EmbeddedField
- type EmbeddedResolveFilter
- type EmbeddedResolver
- type Field
- type File
- type Import
- type Interface
- type Method
- type MethodParam
- type MethodResult
- type Package
- func NewPackage(pkgPath string, files []*File) *Package
- func NewPackageFromAstPackage(pkgPath string, astPkg *ast.Package) *Package
- func NewPackageFromFilenames(pkgPath string, filenames ...string) (*Package, error)
- func NewPackageFromFilenamesWithOpts(pkgPath string, mode parser.Mode, filenames ...string) (*Package, error)
- func PackagesFromDirs(pkgDirs map[string]string) ([]*Package, error)
- func PackagesFromDirsWithOpts(pkgDirs map[string]string, filter func(fs.FileInfo) bool, mode parser.Mode) ([]*Package, error)
- func SinglePackageFromDir(pkgPath string, dir string) (*Package, error)
- func SinglePackageFromDirWithOpts(pkgPath string, dir string, filter func(fs.FileInfo) bool, mode parser.Mode) (*Package, error)
- type Struct
- type TemplateData
Constants ¶
const DefaultParseMode = parser.AllErrors | parser.ParseComments
Variables ¶
This section is empty.
Functions ¶
func GenerateLayer ¶
func IsPrivate ¶
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 SetPackageOnType ¶
SetPackageOnType sets the package in the type. e.g., hexa, Health => hexa.Health e.g., hexa, []*Health => []*hexa.Health
func UseTypeInPackage ¶
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 ¶
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 ¶
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 (*File) FindInterface ¶
func (*File) FindStruct ¶
type Interface ¶
type Interface struct { Doc string Annotations Annotations Name string Embedded []*EmbeddedField Methods []*Method }
func UseInterfaceInPackage ¶
UseInterfaceInPackage updates the interface to be able to use it in another package.
func (*Interface) MethodByName ¶
type Method ¶
type Method struct { Doc string Annotations Annotations Name string Params []*MethodParam Results []*MethodResult }
func UseMethodsInPackage ¶
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 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 NewPackageFromFilenames ¶
func PackagesFromDirs ¶
PackagesFromDirs returns list of packages. pkgDirs params is a map from package's path to the dir path.
type Struct ¶
type Struct struct { Doc string Annotations Annotations Name string Embedded []*EmbeddedField Fields []*Field }
func UseStructInPackage ¶
UseStructInPackage updates the struct to be able to use it in another package.