generator

package
v1.9.8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const BuilderTemplate = `` /* 8665-byte string literal not displayed */

BuilderTemplate is the template for generating builder code

View Source
const RegistryTemplate = `` /* 1571-byte string literal not displayed */

RegistryTemplate contains the builder registry code

Variables

View Source
var DefaultRegistry = NewBuilderRegistry()

DefaultRegistry is the default builder registry

Functions

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake converts a camelCase string to snake_case

func GetAll

func GetAll() map[string]BuilderFunc

GetAll returns all registered builder functions from the default registry

func Register

func Register(name string, fn BuilderFunc)

Register registers a builder function with the default registry

func SnakeToCamel

func SnakeToCamel(s string) string

SnakeToCamel converts a snake_case string to camelCase

func ToLowerFirst

func ToLowerFirst(s string) string

ToLowerFirst converts the first character of a string to lowercase

func ToParamName

func ToParamName(s string) string

ToParamName converts a field name to a parameter name Examples: ID -> id, UserID -> userID, HTTPRequest -> httpRequest

func ToSingular

func ToSingular(s string) string

ToSingular converts a plural field name to singular Examples: Friends -> Friend, Addresses -> Address, Children -> Child

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a string from CamelCase to snake_case

Types

type Builder

type Builder interface {
	Build() any
}

Builder is the interface that all builders must implement

func CreateBuilder

func CreateBuilder(typeName string) (Builder, error)

CreateBuilder creates a new builder for the given type using the default registry

type BuilderFunc

type BuilderFunc func() Builder

BuilderFunc is a function that creates a new builder

func Get

func Get(name string) (BuilderFunc, bool)

Get returns a builder function by name from the default registry

type BuilderRegistry

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

BuilderRegistry manages builder functions

func NewBuilderRegistry

func NewBuilderRegistry() *BuilderRegistry

NewBuilderRegistry creates a new BuilderRegistry

func (*BuilderRegistry) CreateBuilder

func (r *BuilderRegistry) CreateBuilder(typeName string) (Builder, error)

CreateBuilder creates a new builder for the given type

func (*BuilderRegistry) Get

func (r *BuilderRegistry) Get(name string) (BuilderFunc, bool)

Get returns a builder function by name

func (*BuilderRegistry) GetAll

func (r *BuilderRegistry) GetAll() map[string]BuilderFunc

GetAll returns all registered builder functions

func (*BuilderRegistry) Register

func (r *BuilderRegistry) Register(name string, fn BuilderFunc)

Register registers a builder function

type Generator

type Generator struct {
	Options Options
}

Generator generates builder code for structs

func NewGenerator

func NewGenerator(opts Options) *Generator

NewGenerator creates a new Generator

func (*Generator) GenerateBuilders

func (g *Generator) GenerateBuilders(inputFile, outputDir string) error

GenerateBuilders generates builders for all structs in a Go file

func (*Generator) ProcessDirectory

func (g *Generator) ProcessDirectory(inputDir, outputDir string, recursive bool) error

ProcessDirectory processes all Go files in a directory and generates builders for all structs

func (*Generator) ProcessFile

func (g *Generator) ProcessFile(inputFile, outputDir string) error

ProcessFile processes a single Go file and generates builders for all structs

type Options

type Options struct {
	PackageName   string
	ModelsPackage string
	Verbose       bool
}

Options contains options for the generator

type StructField

type StructField struct {
	Name         string
	Type         string
	IsPointer    bool
	IsSlice      bool
	IsMap        bool
	IsNested     bool
	IsBuiltin    bool
	ElementType  string // For slices
	KeyType      string // For maps
	ValType      string // For maps
	ImportNeeded string // Import path needed for this field
	BuilderName  string // Name of the builder for nested structs
}

StructField represents a field in a struct

type StructInfo

type StructInfo struct {
	Name   string
	Fields []StructField
}

StructInfo represents information about a struct

Jump to

Keyboard shortcuts

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