generator

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const TemplateName = `ARPkgTemplate`

Variables

View Source
var MetaTmpl string
View Source
var OctopusFixtureRepositoryTmpl string
View Source
var OctopusFormatMapper = map[octopus.Format]OctopusFormatParam{
	octopus.Bool:    {Name: "Uint8", UnpackConvFunc: "octopus.UintToBool", /* contains filtered or unexported fields */},
	octopus.Uint8:   {Name: "Uint8", /* contains filtered or unexported fields */},
	octopus.Uint16:  {Name: "Uint16", /* contains filtered or unexported fields */},
	octopus.Uint32:  {Name: "Uint32", /* contains filtered or unexported fields */},
	octopus.Uint64:  {Name: "Uint64", /* contains filtered or unexported fields */},
	octopus.Uint:    {Name: "Uint32", UnpackConvFunc: "uint", /* contains filtered or unexported fields */},
	octopus.Int8:    {Name: "Uint8", UnpackConvFunc: "int8", /* contains filtered or unexported fields */},
	octopus.Int16:   {Name: "Uint16", UnpackConvFunc: "int16", /* contains filtered or unexported fields */},
	octopus.Int32:   {Name: "Uint32", UnpackConvFunc: "int32", /* contains filtered or unexported fields */},
	octopus.Int64:   {Name: "Uint64", UnpackConvFunc: "int64", /* contains filtered or unexported fields */},
	octopus.Int:     {Name: "Uint32", UnpackConvFunc: "int", /* contains filtered or unexported fields */},
	octopus.Float32: {Name: "Uint32", UnpackConvFunc: "math.Float32frombits", /* contains filtered or unexported fields */},
	octopus.Float64: {Name: "Uint64", UnpackConvFunc: "math.Float64frombits", /* contains filtered or unexported fields */},
	octopus.String:  {Name: "String", /* contains filtered or unexported fields */}}
View Source
var OctopusMockRepositoryTmpl string
View Source
var OctopusMutatorMapper = map[string]OctopusMutatorParam{
	ds.IncMutator:      {Name: "Inc", AvailableType: octopus.NumericFormat},
	ds.DecMutator:      {Name: "Dec", AvailableType: octopus.NumericFormat},
	ds.AndMutator:      {Name: "And", AvailableType: octopus.UnsignedFormat},
	ds.OrMutator:       {Name: "Or", AvailableType: octopus.UnsignedFormat},
	ds.XorMutator:      {Name: "Xor", AvailableType: octopus.UnsignedFormat},
	ds.ClearBitMutator: {Name: "ClearBit", AvailableType: octopus.UnsignedFormat},
	ds.SetBitMutator:   {Name: "SetBit", AvailableType: octopus.UnsignedFormat},
}
View Source
var OctopusRootRepositoryTmpl string
View Source
var OctopusTemplateFuncs = template.FuncMap{
	"packerParam": func(format octopus.Format) OctopusFormatParam {
		ret, ex := OctopusFormatMapper[format]
		if !ex {
			log.Fatalf("packer for type `%s` not found", format)
		}

		return ret
	},
	"mutatorParam": func(mut string, format octopus.Format) OctopusMutatorParam {
		ret, ex := OctopusMutatorMapper[mut]
		if !ex {
			log.Fatalf("mutator packer for type `%s` not found", format)
		}

		for _, availFormat := range ret.AvailableType {
			if availFormat == format {
				return ret
			}
		}

		log.Fatalf("Mutator `%s` not available for type `%s`", mut, format)

		return OctopusMutatorParam{}
	},
	"addImport": func(flds []ds.FieldDeclaration) (imports []string) {
		var needMath, needStrconv bool

		for _, fld := range flds {
			if fld.Format == octopus.Float32 || fld.Format == octopus.Float64 {
				needMath = true
			}

			if len(fld.Mutators) > 0 && fld.Format != "uint32" && fld.Format != "uint64" && fld.Format != "uint" {
				needMath = true
			}

			if fld.PrimaryKey && fld.Format != "string" {
				needStrconv = true
			}
		}

		if needMath {
			imports = append(imports, "math")
		}

		if needStrconv {
			imports = append(imports, "strconv")
		}

		return
	},
	"trimPrefix": strings.TrimPrefix,
	"hasPrefix":  strings.HasPrefix,
}
View Source
var PrimitiveTypeFormatConverter = map[octopus.Format]TarantoolFormatParam{
	octopus.Bool:    "strconv.FormatBool(%%)",
	octopus.Uint8:   "strconv.FormatUint(uint64(%%), 10)",
	octopus.Uint16:  "strconv.FormatUint(uint64(%%), 10)",
	octopus.Uint32:  "strconv.FormatUint(uint64(%%), 10)",
	octopus.Uint64:  "strconv.FormatUint(%%, 10)",
	octopus.Uint:    "strconv.FormatUint(uint64(%%), 10)",
	octopus.Int8:    "strconv.FormatInt(int64(%%), 10)",
	octopus.Int16:   "strconv.FormatInt(int64(%%), 10)",
	octopus.Int32:   "strconv.FormatInt(int64(%%), 10)",
	octopus.Int64:   "strconv.FormatInt(%%, 10)",
	octopus.Int:     "strconv.FormatInt(int64(%%), 10)",
	octopus.Float32: "strconv.FormatFloat(%%, 32)",
	octopus.Float64: "strconv.FormatFloat(%%, 64)",
	octopus.String:  "%%",
}
View Source
var Tarantool2TmplFunc = template.FuncMap{
	"packerParam": func(format octopus.Format) TarantoolFormatParam {
		ret, ex := PrimitiveTypeFormatConverter[format]
		if !ex {
			log.Fatalf("packer for type `%s` not found", format)
		}

		return ret
	},
	"addImport": func(flds []ds.FieldDeclaration) (imports []string) {
		var needStrconv bool

		for _, fld := range flds {
			if fld.PrimaryKey && fld.Format != "string" {
				needStrconv = true
			}
		}

		if needStrconv {
			imports = append(imports, "strconv")
		}

		return
	},
	"trimPrefix":       strings.TrimPrefix,
	"hasPrefix":        strings.HasPrefix,
	"lowerCase":        strings.ToLower,
	"snakeToCamelCase": text.SnakeToCamelCase,
}

Functions

func ErrorLine

func ErrorLine(errIn error, genData string) error

func GenerateByTmpl

func GenerateByTmpl(dstFile io.Writer, params any, name, tmpl string, tmplFuncs ...template.FuncMap) *arerror.ErrGeneratorPhases

func GenerateOctopus

func GenerateOctopus(params PkgData) (map[string]bytes.Buffer, *arerror.ErrGeneratorPhases)

func GenerateOctopusFixtureStore added in v1.12.0

func GenerateOctopusFixtureStore(params FixturePkgData) (map[string]bytes.Buffer, *arerror.ErrGeneratorPhases)

func GenerateTarantool added in v1.12.0

func GenerateTarantool(params PkgData) (map[string]bytes.Buffer, *arerror.ErrGeneratorPhases)

func GenerateTarantoolFixtureStore added in v1.12.0

func GenerateTarantoolFixtureStore(params FixturePkgData) (map[string]bytes.Buffer, *arerror.ErrGeneratorPhases)

Types

type FixtureMetaData added in v1.12.0

type FixtureMetaData struct {
	MetaData
	FixturePkg string
}

type FixturePkgData added in v1.8.0

type FixturePkgData struct {
	FixturePkg       string
	ARPkg            string
	ARPkgTitle       string
	FieldList        []ds.FieldDeclaration
	FieldMap         map[string]int
	FieldObject      map[string]ds.FieldObject
	ProcInFieldList  []ds.ProcFieldDeclaration
	ProcOutFieldList []ds.ProcFieldDeclaration
	Container        ds.NamespaceDeclaration
	Indexes          []ds.IndexDeclaration
	Serializers      map[string]ds.SerializerDeclaration
	Mutators         map[string]ds.MutatorDeclaration
	Imports          []ds.ImportDeclaration
	AppInfo          string
}

type GenerateFile

type GenerateFile struct {
	Data    []byte
	Name    string
	Dir     string
	Backend string
}

func Generate

func Generate(appInfo string, cl ds.RecordPackage, linkObject map[string]ds.RecordPackage) (ret []GenerateFile, err error)

func GenerateFixture

func GenerateFixture(appInfo string, cl ds.RecordPackage, pkg string, pkgFixture string) ([]GenerateFile, error)

func GenerateFixtureMeta added in v1.12.0

func GenerateFixtureMeta(packageNamespaces map[string][]*ds.RecordPackage, appInfo, pkgFixture string) ([]GenerateFile, error)

func GenerateMeta

func GenerateMeta(params MetaData) ([]GenerateFile, *arerror.ErrGeneratorFile)

type MetaData

type MetaData struct {
	Namespaces []*ds.RecordPackage
	AppInfo    string
}

type OctopusFormatParam

type OctopusFormatParam struct {
	Name    string
	Default []byte

	UnpackConvFunc string
	// contains filtered or unexported fields
}

func (OctopusFormatParam) DefaultValue

func (p OctopusFormatParam) DefaultValue() string

func (OctopusFormatParam) Len

func (p OctopusFormatParam) Len(l uint32) uint

func (OctopusFormatParam) MaxValue

func (p OctopusFormatParam) MaxValue() string

func (OctopusFormatParam) MinValue

func (p OctopusFormatParam) MinValue() string

func (OctopusFormatParam) MutatorTypeConv

func (p OctopusFormatParam) MutatorTypeConv() string

func (OctopusFormatParam) PackConvFunc

func (p OctopusFormatParam) PackConvFunc(fieldname string) string

func (OctopusFormatParam) PackFunc

func (p OctopusFormatParam) PackFunc() string

func (OctopusFormatParam) ToString

func (p OctopusFormatParam) ToString() []string

func (OctopusFormatParam) UnpackFunc

func (p OctopusFormatParam) UnpackFunc() string

func (OctopusFormatParam) UnpackType

func (p OctopusFormatParam) UnpackType() string

type OctopusMutatorParam

type OctopusMutatorParam struct {
	Name          string
	AvailableType []octopus.Format
	ArgType       string
}

type PkgData

type PkgData struct {
	ARPkg            string
	ARPkgTitle       string
	FieldList        []ds.FieldDeclaration
	FieldMap         map[string]int
	FieldObject      map[string]ds.FieldObject
	LinkedObject     map[string]ds.RecordPackage
	ProcInFieldList  []ds.ProcFieldDeclaration
	ProcOutFieldList []ds.ProcFieldDeclaration
	Server           ds.ServerDeclaration
	Container        ds.NamespaceDeclaration
	Indexes          []ds.IndexDeclaration
	Serializers      map[string]ds.SerializerDeclaration
	Mutators         map[string]ds.MutatorDeclaration
	Imports          []ds.ImportDeclaration
	Triggers         map[string]ds.TriggerDeclaration
	Flags            map[string]ds.FlagDeclaration
	AppInfo          string
}

func NewPkgData

func NewPkgData(appInfo string, cl ds.RecordPackage) PkgData

type TarantoolFormatParam added in v1.12.0

type TarantoolFormatParam string

func (TarantoolFormatParam) ToString added in v1.12.0

func (p TarantoolFormatParam) ToString() []string

Jump to

Keyboard shortcuts

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