Documentation
¶
Index ¶
- Constants
- Variables
- func FormatType(parameter reflection.Parameter) string
- func FormattedCallParameters(m reflection.Method) string
- func FormattedParameters(m reflection.Method) string
- func FormattedResultParameters(m reflection.Method) string
- func FormattedResultTypes(m reflection.Method) string
- func GetGoFilePath() (string, error)
- func GoFileAccessor() reflection.AstFileAccessor
- func HasResults(m reflection.Method) bool
- func MakePrivate(s string) string
- func MakePublic(s string) string
- func RegisterNamingFunctions(generator GenericCodeGenerator) error
- func RegisterTemplateFunctions(g GenericCodeGenerator, ...) error
- func RegisterTypeModelFunctions(generator GenericCodeGenerator) error
- func Signature(m reflection.Method) string
- type BootstrapGenerator
- type CodeFileGenerator
- type CodeFileGeneratorOptions
- type CodeFileGeneratorOptionsFunc
- type GenericCodeGenerator
- type GoProject
- type OutputWriterFactory
- type ProjectError
- type ProjectItem
- type ScaffoldingFileWriterFunc
- type TemplateFunction
- type TemplateLoader
- type TemplateModelBuilder
Constants ¶
const ( ErrorCannotExecuteTemplate = "cannot execute template" ErrorCannotFormatGeneratedCode = "cannot format generated code" ErrorCannotGenerateProxies = "cannot generate proxies" ErrorFailedToOpenTemplateFile = "failed to open template file" ErrorFailedToWriteGeneratedCode = "failed to write generated code" ErrorTemplateFileNotFound = "template file not found" ErrorFailedToObtainGeneratorSourceFile = "failed to obtain generator source file" )
Variables ¶
var ( ErrCannotExecuteTemplate = errors.New(ErrorCannotExecuteTemplate) ErrCannotFormatGeneratedCode = errors.New(ErrorCannotFormatGeneratedCode) ErrCannotGenerateProxies = errors.New(ErrorCannotGenerateProxies) ErrFailedToOpenTemplateFile = errors.New(ErrorFailedToOpenTemplateFile) ErrFailedToWriteGeneratedCode = errors.New(ErrorFailedToWriteGeneratedCode) ErrTemplateFileNotFound = errors.New(ErrorTemplateFileNotFound) ErrFailedToObtainGeneratorSourceFile = errors.New(ErrorFailedToObtainGeneratorSourceFile) )
var ( ErrCannotReadModFile = errors.New(errorCannotReadModFile) ErrCannotParseModFile = errors.New(errorCannotParseModFile) ErrFailedToAddRequiredDependency = errors.New(errorFailedToAddRequiredDependency) ErrCannotFormatModFile = errors.New(errorCannotFormatModFile) ErrCannotWriteModFile = errors.New(errorCannotWriteModFile) )
Functions ¶
func FormatType ¶
func FormatType(parameter reflection.Parameter) string
FormatType formats the given reflection.Parameter's type information into a string representation.
func FormattedCallParameters ¶
func FormattedCallParameters(m reflection.Method) string
FormattedCallParameters formats the call parameters of the given reflection.Method into a comma-separated string.
func FormattedParameters ¶
func FormattedParameters(m reflection.Method) string
FormattedParameters formats the parameters of the given reflection.Method into a comma-separated string with type info.
func FormattedResultParameters ¶
func FormattedResultParameters(m reflection.Method) string
FormattedResultParameters formats the result parameters of the given reflection.Method into a comma-separated string.
func FormattedResultTypes ¶
func FormattedResultTypes(m reflection.Method) string
FormattedResultTypes formats the result types of the given reflection.Method into a string representation.
func GetGoFilePath ¶
func GoFileAccessor ¶
func GoFileAccessor() reflection.AstFileAccessor
GoFileAccessor Creates a new reflection.AstFileAccessor object that reads a source file from the GOFILE variable.
func HasResults ¶
func HasResults(m reflection.Method) bool
HasResults checks if the given reflection.Method has any result parameters.
func MakePrivate ¶
func MakePublic ¶
func RegisterNamingFunctions ¶
func RegisterNamingFunctions(generator GenericCodeGenerator) error
func RegisterTemplateFunctions ¶
func RegisterTemplateFunctions(g GenericCodeGenerator, functions ...func(generator GenericCodeGenerator) error) error
func RegisterTypeModelFunctions ¶
func RegisterTypeModelFunctions(generator GenericCodeGenerator) error
RegisterTypeModelFunctions registers a series of functions for type model processing in the given code generator.
func Signature ¶
func Signature(m reflection.Method) string
Signature generates the signature string of a given method.
Types ¶
type BootstrapGenerator ¶
type BootstrapGenerator interface {
ScaffoldProjectFiles()
}
BootstrapGenerator provides functionalities to scaffold project files.
func NewBootstrapGenerator ¶
func NewBootstrapGenerator(writerFunc ScaffoldingFileWriterFunc) BootstrapGenerator
NewBootstrapGenerator initializes and returns a BootstrapGenerator with the specified project folder path.
type CodeFileGenerator ¶
type CodeFileGenerator interface {
GenerateCode() error
}
func NewCodeFileGenerator ¶
func NewCodeFileGenerator(kind string, fileAccessor reflection.AstFileAccessor, config ...CodeFileGeneratorOptionsFunc) (CodeFileGenerator, error)
type CodeFileGeneratorOptions ¶
type CodeFileGeneratorOptions struct { TemplateLoader TemplateLoader ConfigureModelCallback reflection.ModelConfigurationFunc OutputWriterFactory OutputWriterFactory // contains filtered or unexported fields }
type CodeFileGeneratorOptionsFunc ¶
type CodeFileGeneratorOptionsFunc func(config *CodeFileGeneratorOptions)
type GenericCodeGenerator ¶
type GenericCodeGenerator interface { AddTemplateFunc(functions ...TemplateFunction) error Generate(templateName string, model any, writer io.Writer) error }
func NewGenericCodeGenerator ¶
func NewGenericCodeGenerator(templateLoader TemplateLoader) GenericCodeGenerator
type GoProject ¶
func OpenProject ¶
OpenProject opens an existing Go project from the specified folder path and returns a GoProject instance.
type OutputWriterFactory ¶
type OutputWriterFactory func(kind string, source *reflection.AstFileSource) (io.WriteCloser, error)
func FileOutputWriter ¶
func FileOutputWriter() OutputWriterFactory
FileOutputWriter Creates an OutputWriterFactory object that can be used create file writers.
type ProjectError ¶
type ProjectError struct {
// contains filtered or unexported fields
}
func (ProjectError) Error ¶
func (e ProjectError) Error() string
func (ProjectError) Is ¶
func (e ProjectError) Is(err error) bool
func (ProjectError) Unwrap ¶
func (e ProjectError) Unwrap() error
type ProjectItem ¶
ProjectItem represents a template file and its corresponding target filename in a project scaffold.
type ScaffoldingFileWriterFunc ¶
type ScaffoldingFileWriterFunc func(targetFilename string) (io.WriteCloser, error)
type TemplateFunction ¶
func NamedFunc ¶
func NamedFunc(name string, f any) TemplateFunction
type TemplateLoader ¶
type TemplateModelBuilder ¶
type TemplateModelBuilder struct {
// contains filtered or unexported fields
}
func NewTemplateModelBuilder ¶
func NewTemplateModelBuilder(file *ast.File) *TemplateModelBuilder
func (*TemplateModelBuilder) Build ¶
func (b *TemplateModelBuilder) Build() (*reflection.Model, error)