Documentation
¶
Index ¶
- Constants
- Variables
- func CamelToSnake(s string) string
- func GetAll() map[string]BuilderFunc
- func Register(name string, fn BuilderFunc)
- func SnakeToCamel(s string) string
- func ToLowerFirst(s string) string
- func ToParamName(s string) string
- func ToSingular(s string) string
- func ToSnakeCase(s string) string
- type Builder
- type BuilderFunc
- type BuilderRegistry
- type Generator
- type Options
- type StructField
- type StructInfo
Constants ¶
const BuilderTemplate = `` /* 8665-byte string literal not displayed */
BuilderTemplate is the template for generating builder code
const RegistryTemplate = `` /* 1571-byte string literal not displayed */
RegistryTemplate contains the builder registry code
Variables ¶
var DefaultRegistry = NewBuilderRegistry()
DefaultRegistry is the default builder registry
Functions ¶
func CamelToSnake ¶
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 ¶
SnakeToCamel converts a snake_case string to camelCase
func ToLowerFirst ¶
ToLowerFirst converts the first character of a string to lowercase
func ToParamName ¶
ToParamName converts a field name to a parameter name Examples: ID -> id, UserID -> userID, HTTPRequest -> httpRequest
func ToSingular ¶
ToSingular converts a plural field name to singular Examples: Friends -> Friend, Addresses -> Address, Children -> Child
func ToSnakeCase ¶
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 ¶
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 (*Generator) GenerateBuilders ¶
GenerateBuilders generates builders for all structs in a Go file
func (*Generator) ProcessDirectory ¶
ProcessDirectory processes all Go files in a directory and generates builders for all structs
func (*Generator) ProcessFile ¶
ProcessFile processes a single Go file and generates builders for all structs
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