constago

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(config *Config) error

func NewModelBuilder

func NewModelBuilder(config *Config) *modelBuilder

Types

type Config

type Config struct {
	Input    ConfigInput    `yaml:"input"`
	Output   ConfigOutput   `yaml:"output"`
	Elements []ConfigTag    `yaml:"elements"`
	Getters  []ConfigGetter `yaml:"getters"`
}

Config represents the main configuration structure for the Constago generator

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads and parses the configuration from a YAML file

func NewConfig

func NewConfig(config *Config) (*Config, error)

type ConfigGetter

type ConfigGetter struct {
	Name    string             `yaml:"name"`
	Returns []string           `yaml:"returns"`
	Output  ConfigGetterOutput `yaml:"output"`
}

config.getters[i]

type ConfigGetterOutput

type ConfigGetterOutput struct {
	Prefix string             `yaml:"prefix"`
	Suffix string             `yaml:"suffix"`
	Format ConstantFormatType `yaml:"format"`
}

type ConfigInput

type ConfigInput struct {
	Include []string `yaml:"include"`
	Exclude []string `yaml:"exclude"`

	Dir string `yaml:"dir"`

	Struct ConfigInputStruct `yaml:"struct"`
	Field  ConfigInputField  `yaml:"field"`
}

config.input

type ConfigInputField

type ConfigInputField struct {
	Explicit          *bool  `yaml:"explicit"`
	IncludeUnexported *bool  `yaml:"include_unexported"`
	Only              string `yaml:"only"`
	Except            string `yaml:"except"`
}

type ConfigInputStruct

type ConfigInputStruct struct {
	Explicit          *bool  `yaml:"explicit"`
	IncludeUnexported *bool  `yaml:"include_unexported"`
	Only              string `yaml:"only"`
	Except            string `yaml:"except"`
}

type ConfigOutput

type ConfigOutput struct {
	FileName string `yaml:"file_name"`
}

config.output

type ConfigTag

type ConfigTag struct {
	Name string `yaml:"name"`

	Input  ConfigTagInput  `yaml:"input"`
	Output ConfigTagOutput `yaml:"output"`
}

config.tags[i]

type ConfigTagInput

type ConfigTagInput struct {
	Mode        InputModeType `yaml:"mode"`
	TagPriority []string      `yaml:"tag_priority"`
}

type ConfigTagOutput

type ConfigTagOutput struct {
	Mode      OutputModeType           `yaml:"mode"`
	Format    ConfigTagOutputFormat    `yaml:"format"`
	Transform ConfigTagOutputTransform `yaml:"transform"`
}

type ConfigTagOutputFormat

type ConfigTagOutputFormat struct {
	Holder ConstantFormatType `yaml:"holder"`
	Struct ConstantFormatType `yaml:"struct"`
	Prefix string             `yaml:"prefix"`
	Suffix string             `yaml:"suffix"`
}

type ConfigTagOutputTransform

type ConfigTagOutputTransform struct {
	TagValues      *bool             `yaml:"tag_values"`
	ValueCase      TransformCaseType `yaml:"value_case"`
	ValueSeparator string            `yaml:"value_separator"`
}

type ConstantFormatType

type ConstantFormatType string

ConstantFormatType

const (
	ConstantFormatCamel      ConstantFormatType = "camel"
	ConstantFormatPascal     ConstantFormatType = "pascal"
	ConstantFormatSnake      ConstantFormatType = "snake"
	ConstantFormatSnakeUpper ConstantFormatType = "snakeUpper"
)

type ConstantOutput

type ConstantOutput struct {
	Name  string
	Value string
}

type FieldOutput

type FieldOutput struct {
	StructName string
	Name       string
	Value      string
}

type GetterOutput

type GetterOutput struct {
	Name    string
	Returns []*ReturnOutput
}

type InputModeType

type InputModeType string

InputModeType

const (
	InputModeTypeTagThenField InputModeType = "tagThenField"
	InputModeTypeField        InputModeType = "field"
	InputModeTypeTag          InputModeType = "tag"
)

type Model

type Model struct {
	// Packages organized by path
	Packages map[string]*PackageModel

	// Scanning statistics
	FilesScanned  int
	PackagesFound int
	StructsFound  int
	FieldsFound   int

	// Errors encountered during scanning
	Errors []*ScanError
}

func NewModel

func NewModel(config *Config) *Model

func (*Model) AddError

func (m *Model) AddError(file string, line int, message string)

AddError appends a scanning error to the model

func (*Model) AddStruct

func (m *Model) AddStruct(packagePath string, packageName string, structModel *StructModel)

type NoneOutput

type NoneOutput struct {
	Name  string
	Value string
}

type OutputModeType

type OutputModeType string

OutputModeType

const (
	OutputModeNone     OutputModeType = "none"
	OutputModeStruct   OutputModeType = "struct"
	OutputModeConstant OutputModeType = "constant"
)

type PackageModel

type PackageModel struct {
	// Package information
	Name string
	Path string

	// Imports to use in the generated code
	Imports map[string]*TypePackageOutput

	// Structs to generate validators for
	Structs []*StructModel
}

type ReturnOutput

type ReturnOutput struct {
	Field    *FieldOutput
	Constant *ConstantOutput
	None     *NoneOutput
	Value    *ValueOutput
}

type ScanError

type ScanError struct {
	File    string
	Line    int
	Message string
}

type StructModel

type StructModel struct {
	Name       string
	File       string
	LineNumber int

	// Fields that should have code to generate
	Constants []*ConstantOutput
	Structs   []*StructOutput
	Getters   []*GetterOutput
}

StructInfo represents a struct that should have code to generate

type StructOutput

type StructOutput struct {
	Name    string
	Package string

	Fields []*FieldOutput
}

type TransformCaseType

type TransformCaseType string

TransformCaseType

const (
	TransformCaseAsIs   TransformCaseType = "asIs"
	TransformCaseCamel  TransformCaseType = "camel"
	TransformCasePascal TransformCaseType = "pascal"
	TransformCaseUpper  TransformCaseType = "upper"
	TransformCaseLower  TransformCaseType = "lower"
)

type TypePackageOutput

type TypePackageOutput struct {
	Path  string
	Name  string
	Alias string
}

type ValueOutput

type ValueOutput struct {
	FieldName   string
	TypeName    string
	TypePackage *TypePackageOutput
}

Jump to

Keyboard shortcuts

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