Documentation
¶
Index ¶
- Variables
- func GenerateGORMServices(cfg *config.Config, structMetaData []StructMeta) (err error)
- func GetModulePath(targetDir string) (string, error)
- func GetPreloadMap(structs []StructMeta, preloadDepth uint) map[string][]string
- func Map(data []StructMeta) (m map[string]StructMeta)
- type Arg
- type Field
- type Function
- type StructMeta
Constants ¶
This section is empty.
Variables ¶
var ValidationText = `` /* 3601-byte string literal not displayed */
Functions ¶
func GenerateGORMServices ¶
func GenerateGORMServices(cfg *config.Config, structMetaData []StructMeta) (err error)
generateServices generates the service.go file
func GetModulePath ¶
Returns the go import path for a given directory targetDir
func GetPreloadMap ¶
func GetPreloadMap(structs []StructMeta, preloadDepth uint) map[string][]string
GetPreloadMap returns a map of struct names to their respective preload fields, including nested relationships.
func Map ¶
func Map(data []StructMeta) (m map[string]StructMeta)
Create a StructMeta map from slice.
Types ¶
type Field ¶
type Field struct { Name string // Field Exact name Type string // Full data type for the field BaseType string // Base type stripped of [] or pointers Tag string // Unmodified struct tag. Preload bool // Whether this is a foreignKey or many2many field to preload. Parent string // Parent struct Name }
Field contains meta-data for each struct field.
type Function ¶
type Function struct { Name string Pkg string Receiver string PointerRecv bool Args []Arg ReturnTypes []Arg }
func ParseFunctions ¶
ParseFunctions parses Go source code and returns a slice of functions that are declared in the code. It supports functions with pointer receivers, variadic arguments, and return types that are not simple identifiers.
Returns: A slice of Function structs, each representing a function declared in the input code.
Example:
functions := ParseFunctions(` package main import "fmt" type Person struct { Name string Age int } func (p *Person) Greet(other *Person, msg string) (greeting string, err error) { return fmt.Sprintf("%s says hello to %s", p.Name, other.Name), nil } func (p Person) Grow(n int) []int { return make([]int, n) } `) for _, fxn := range functions { fmt.Println(fxn.Name) fmt.Println(fxn.Pkg) fmt.Println(fxn.PointerRecv) for _, arg := range fxn.Args { fmt.Printf("%s %s %v\n", arg.Name, arg.Type, arg.IsPointer) } for _, ret := range fxn.ReturnTypes { fmt.Printf("%s %s %v\n", ret.Name, ret.Type, ret.IsPointer) } }
type StructMeta ¶
type StructMeta struct { Name string // Model name e.g User PKType string // PKType e.g int, int64 etc Fields []Field // Fields for struct fields that are builtin(only) Package string // Package name e.g "github.com/username/module/models" Skip bool // Skip generating service for this struct }
StructMeta contains metadata about the struct generated by the go/ast.
func Parse ¶
func Parse(modelPkgs []string) []StructMeta
Parse structs in package pkg and return Struct metadata about them.