generator

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// KnownTypeMap is the collection of known Go types.
	KnownTypeMap = map[string]bool{
		"bool":        true,
		"string":      true,
		"byte":        true,
		"rune":        true,
		"int":         true,
		"int8":        true,
		"int16":       true,
		"int32":       true,
		"int64":       true,
		"uint":        true,
		"uint8":       true,
		"uint16":      true,
		"uint32":      true,
		"uint64":      true,
		"float32":     true,
		"float64":     true,
		"Slice":       true,
		"StringSlice": true,
	}

	ShortNameTypeMap = map[string]string{
		"bool":    "b",
		"string":  "s",
		"byte":    "b",
		"rune":    "r",
		"int":     "i",
		"int8":    "i",
		"int16":   "i",
		"int32":   "i",
		"int64":   "i",
		"uint":    "u",
		"uint8":   "u",
		"uint16":  "u",
		"uint32":  "u",
		"uint64":  "u",
		"float32": "f",
		"float64": "f",
	}

	ConflictedShortNames = map[string]bool{
		"context":  true,
		"errors":   true,
		"fmt":      true,
		"regexp":   true,
		"strings":  true,
		"time":     true,
		"iterator": true,
		"spanner":  true,
		"civil":    true,
		"codes":    true,
		"status":   true,
	}
)

Functions

func CopyDefaultTemplates

func CopyDefaultTemplates(dir string) error

CopyDefaultTemplates copies default templete files to dir.

Types

type Generator

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

func NewGenerator

func NewGenerator(loader Loader, inflector internal.Inflector, opt GeneratorOption) *Generator

func (*Generator) ExecuteTemplate

func (g *Generator) ExecuteTemplate(tt TemplateType, name string, sub string, obj interface{}) error

ExecuteTemplate loads and parses the supplied template with name and executes it with obj as the context.

func (*Generator) Generate

func (g *Generator) Generate(tableMap map[string]*internal.Type, ixMap map[string]*internal.Index) error

type GeneratorOption

type GeneratorOption struct {
	PackageName        string
	Tags               string
	TemplatePath       string
	CustomTypePackage  string
	FilenameSuffix     string
	SingleFile         bool
	Filename           string
	FilenameUnderscore bool
	Path               string
}

type Loader

type Loader interface {
	// NthParam returns the 0-based Nth param for the Loader.
	NthParam(i int) string
}

Loader is the common interface for database drivers that can generate code from a database schema.

type TBuf

type TBuf struct {
	TemplateType TemplateType
	Name         string
	Subname      string
	Buf          *bytes.Buffer
}

TBuf is to hold the executed templates.

type TBufSlice

type TBufSlice []TBuf

TBufSlice is a slice of TBuf compatible with sort.Interface.

func (TBufSlice) Len

func (t TBufSlice) Len() int

func (TBufSlice) Less

func (t TBufSlice) Less(i, j int) bool

func (TBufSlice) Swap

func (t TBufSlice) Swap(i, j int)

type TemplateType

type TemplateType uint

TemplateType represents a template type.

const (
	TypeTemplate TemplateType = iota
	IndexTemplate

	// always last
	YOTemplate
)

the order here will be the alter the output order per file.

func (TemplateType) String

func (tt TemplateType) String() string

String returns the name for the associated template type.

Jump to

Keyboard shortcuts

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