generator

package
v2.0.0-...-9f3f92a Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 16 Imported by: 0

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 FileBuffer

type FileBuffer struct {
	FileName string
	BaseName string

	Header []byte
	Chunks []*TBuf

	TempDir      string
	TempFilePath string
}

func (*FileBuffer) Finalize

func (f *FileBuffer) Finalize() error

func (*FileBuffer) Postprocess

func (f *FileBuffer) Postprocess(disableFormat bool) error

func (*FileBuffer) WriteTempFile

func (f *FileBuffer) WriteTempFile() error

type Generator

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

func NewGenerator

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

func (*Generator) ExecuteHeaderTemplate

func (g *Generator) ExecuteHeaderTemplate(mod module.Module, file *FileBuffer, obj interface{}) error

func (*Generator) ExecuteTemplate

func (g *Generator) ExecuteTemplate(mod module.Module, name 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(schema *models.Schema) error

type GeneratorOption

type GeneratorOption struct {
	PackageName    string
	Tags           string
	FilenameSuffix string
	BaseDir        string
	DisableFormat  bool

	HeaderModule  module.Module
	GlobalModules []module.Module
	TypeModules   []module.Module
}

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 {
	Name 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)

Jump to

Keyboard shortcuts

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