generator

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMapDirectory

func GetMapDirectory(tmpl string) (dir string)

func Match added in v1.2.7

func Match(pattern, content string) (string, error)

func ReadServiceTemplate added in v1.5.0

func ReadServiceTemplate(name string) ([]byte, error)

ReadServiceTemplate reads a service template file by name.

func RegisterInterface

func RegisterInterface(name, content, interfaceTemplate, registerTemplate, importPath string, samePackage bool) (data string, err error)

Types

type Field added in v1.3.0

type Field struct {
	Name             string
	Type             string
	ColumnName       string
	ColumnComment    string
	MultilineComment bool
	Tag              genField.Tag
	GORMTag          genField.GormTag
	CustomGenType    string
	Relation         *genField.Relation
}

Field user input structures

type Options

type Options struct {
	// Code template
	Name              string
	Description       string
	FilePath          string
	Directory         string
	CodeTemplate      string
	InterfaceTemplate string
	RegisterTemplate  string

	// Code attributes - variable
	PackageName        string
	StructName         string
	StructNamePlural   string
	VariableName       string
	VariableNameSnake  string
	VariableNamePlural string
	TableName          string
	ModelName          string
	ServiceName        string

	// Code attributes - import path
	RootPackage  string
	BizPath      string
	StorePath    string
	RequestPath  string
	ModelPath    string
	RelativePath string

	// Service flags
	EnableHTTP     bool
	EnableGRPC     bool
	EnableWS       bool
	WithStore      bool
	WithMiddleware bool
	NoBiz          bool
	NoRouter       bool
	NoHandler      bool

	// Service selection
	Service string // Target service name for path inference

	// Generate by gorm.gen
	Table           string
	FieldTemplate   string
	Fields          string
	MainFields      string
	UpdatableFields string
	MetaFields      []*Field

	// Migration
	TimeStr string
}

func (*Options) GenerateAttributes

func (o *Options) GenerateAttributes(directory string, path string) *Options

func (*Options) GenerateCode

func (o *Options) GenerateCode(tmpl, path string) error

func (*Options) GenerateService added in v1.5.0

func (o *Options) GenerateService(name string) error

GenerateService generates a new service module with configurable HTTP/gRPC servers and business layers.

func (*Options) GetFieldsFromDB

func (o *Options) GetFieldsFromDB() error

func (*Options) InferDirectoryForService added in v1.5.0

func (o *Options) InferDirectoryForService(baseDir, serviceName string) (string, error)

InferDirectoryForService infers the target directory based on service name using a three-tier strategy: 1. Discover services from cmd/ directory (e.g., cmd/myapp-apiserver → "apiserver") 2. Smart replacement: replace service name in path if found as a path segment 3. Fallback: construct internal/{service}/{suffix} pattern

Example: InferDirectoryForService("internal/apiserver/model", "admserver") → "internal/admserver/model"

func (*Options) ReSetDirectory

func (o *Options) ReSetDirectory() *Options

func (*Options) ReadCodeTemplates

func (o *Options) ReadCodeTemplates() *Options

func (*Options) ReadMetaFields added in v1.3.0

func (o *Options) ReadMetaFields() error

func (*Options) Register

func (o *Options) Register(registry config.Registry, interfaceTemplate, registerTemplate, importPath string) error

func (*Options) SetName

func (o *Options) SetName(name string) *Options

type Tmpl

type Tmpl string
const (
	TmplCmd        Tmpl = "cmd"
	TmplModel      Tmpl = "model"
	TmplStore      Tmpl = "store"
	TmplRequest    Tmpl = "request"
	TmplBiz        Tmpl = "biz"
	TmplHandler    Tmpl = "handler"
	TmplMiddleware Tmpl = "middleware"
	TmplJob        Tmpl = "job"
	TmplMigration  Tmpl = "migration"
	TmplSeeder     Tmpl = "seeder"
	TmplService    Tmpl = "service"
)

Jump to

Keyboard shortcuts

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