model

package
v0.0.0-...-4aae350 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeBool = &Type{
		Name:  "bool",
		Scope: &BaseModel,
		Kind:  KindBool,
	}
	TypeByte = &Type{
		Name:  "int8",
		Scope: &BaseModel,
		Kind:  KindInt8,
	}
	TypePbByte = &Type{
		Name:  "byte",
		Scope: &BaseModel,
		Kind:  KindInt8,
	}
	TypeUint8 = &Type{
		Name:  "uint8",
		Scope: &BaseModel,
		Kind:  KindInt8,
	}
	TypeUint16 = &Type{
		Name:  "uint16",
		Scope: &BaseModel,
		Kind:  KindInt16,
	}
	TypeUint32 = &Type{
		Name:  "uint32",
		Scope: &BaseModel,
		Kind:  KindInt32,
	}
	TypeUint64 = &Type{
		Name:  "uint64",
		Scope: &BaseModel,
		Kind:  KindInt64,
	}
	TypeUint = &Type{
		Name:  "uint",
		Scope: &BaseModel,
		Kind:  KindInt,
	}
	TypeInt8 = &Type{
		Name:  "int8",
		Scope: &BaseModel,
		Kind:  KindInt8,
	}
	TypeInt16 = &Type{
		Name:  "int16",
		Scope: &BaseModel,
		Kind:  KindInt16,
	}
	TypeInt32 = &Type{
		Name:  "int32",
		Scope: &BaseModel,
		Kind:  KindInt32,
	}
	TypeInt64 = &Type{
		Name:  "int64",
		Scope: &BaseModel,
		Kind:  KindInt64,
	}
	TypeInt = &Type{
		Name:  "int",
		Scope: &BaseModel,
		Kind:  KindInt,
	}
	TypeFloat32 = &Type{
		Name:  "float32",
		Scope: &BaseModel,
		Kind:  KindFloat64,
	}
	TypeFloat64 = &Type{
		Name:  "float64",
		Scope: &BaseModel,
		Kind:  KindFloat64,
	}
	TypeString = &Type{
		Name:  "string",
		Scope: &BaseModel,
		Kind:  KindString,
	}
	TypeBinary = &Type{
		Name:     "binary",
		Scope:    &BaseModel,
		Kind:     KindSlice,
		Category: CategoryBinary,
		Extra:    []*Type{TypePbByte},
	}

	TypeBaseMap = &Type{
		Name:     "map",
		Scope:    &BaseModel,
		Kind:     KindMap,
		Category: CategoryMap,
	}
	TypeBaseSet = &Type{
		Name:     "set",
		Scope:    &BaseModel,
		Kind:     KindSlice,
		Category: CategorySet,
	}
	TypeBaseList = &Type{
		Name:     "list",
		Scope:    &BaseModel,
		Kind:     KindSlice,
		Category: CategoryList,
	}
)

Functions

func IsBaseType

func IsBaseType(typ *Type) bool

Types

type BoolExpression

type BoolExpression struct {
	Src bool
}

func (BoolExpression) Expression

func (boolExpr BoolExpression) Expression() string

type Category

type Category int64
const (
	CategoryConstant  Category = 1
	CategoryBinary    Category = 8
	CategoryMap       Category = 9
	CategoryList      Category = 10
	CategorySet       Category = 11
	CategoryEnum      Category = 12
	CategoryStruct    Category = 13
	CategoryUnion     Category = 14
	CategoryException Category = 15
	CategoryTypedef   Category = 16
	CategoryService   Category = 17
)

type Choice

type Choice struct {
	MessageName string
	ChoiceName  string
	Type        *Type
}

type Constant

type Constant struct {
	Scope *Model
	Name  string
	Type  *Type
	Value Literal
}

type DoubleExpression

type DoubleExpression struct {
	Src float64
}

func (DoubleExpression) Expression

func (doubleExpr DoubleExpression) Expression() string

type Enum

type Enum struct {
	Scope  *Model
	Name   string
	GoType string
	Values []Constant
}

type Field

type Field struct {
	Scope            *Struct
	Name             string
	Type             *Type
	IsSetDefault     bool
	DefaultValue     Literal
	Required         RequiredNess
	Tags             Tags
	LeadingComments  string
	TrailingComments string
	IsPointer        bool
}

func (Field) GenGoTags

func (f Field) GenGoTags() string

type Function

type Function struct {
	Scope *Model
	Name  string
	Args  []Variable
	Rets  []Variable
	Code  string
}

type IntExpression

type IntExpression struct {
	Src int
}

func (IntExpression) Expression

func (intExpr IntExpression) Expression() string

type Kind

type Kind uint
const (
	KindInvalid Kind = iota
	KindBool
	KindInt
	KindInt8
	KindInt16
	KindInt32
	KindInt64
	KindUint
	KindUint8
	KindUint16
	KindUint32
	KindUint64
	KindUintptr
	KindFloat32
	KindFloat64
	KindComplex64
	KindComplex128
	KindArray
	KindChan
	KindFunc
	KindInterface
	KindMap
	KindPtr
	KindSlice
	KindString
	KindStruct
	KindUnsafePointer
)

type ListExpression

type ListExpression struct {
	ElementType *Type
	Elements    []Literal
}

func (ListExpression) Expression

func (listExpr ListExpression) Expression() string

type Literal

type Literal interface {
	Expression() string
}

type MapExpression

type MapExpression struct {
	KeyType   *Type
	ValueType *Type
	Elements  map[string]Literal
}

func (MapExpression) Expression

func (mapExpr MapExpression) Expression() string

type Method

type Method struct {
	Scope        *Model
	ReceiverName string
	ReceiverType *Type
	ByPtr        bool
	Function
}

type Model

type Model struct {
	FilePath string
	Package  string
	Imports  map[string]*Model //{{import}}:Model

	// rendering data
	PackageName string
	// Imports     map[string]string //{{alias}}:{{import}}
	Typedefs  []TypeDef
	Constants []Constant
	Variables []Variable
	Functions []Function
	Enums     []Enum
	Structs   []Struct
	Methods   []Method
	Oneofs    []Oneof
}

func (Model) IsEmpty

func (m Model) IsEmpty() bool

type Models

type Models []*Model

func (*Models) MergeArray

func (a *Models) MergeArray(b []*Model)

func (*Models) MergeMap

func (a *Models) MergeMap(b map[string]*Model)

type NumberExpression

type NumberExpression struct {
	Src string
}

func (NumberExpression) Expression

func (numExpr NumberExpression) Expression() string

type Oneof

type Oneof struct {
	MessageName   string
	OneofName     string
	InterfaceName string
	Choices       []Choice
}

type RequiredNess

type RequiredNess int
const (
	RequiredNess_Default  RequiredNess = 0
	RequiredNess_Required RequiredNess = 1
	RequiredNess_Optional RequiredNess = 2
)

type StringExpression

type StringExpression struct {
	Src string
}

func (StringExpression) Expression

func (stringExpr StringExpression) Expression() string

type Struct

type Struct struct {
	Scope           *Model
	Name            string
	Fields          []Field
	Category        Category
	LeadingComments string
}

type Tag

type Tag struct {
	Key   string
	Value string
}

type Tags

type Tags []Tag

func (Tags) Len

func (ts Tags) Len() int

func (Tags) Less

func (ts Tags) Less(i, j int) bool

func (*Tags) Remove

func (ts *Tags) Remove(name string)

func (Tags) String

func (ts Tags) String() string

func (Tags) Swap

func (ts Tags) Swap(i, j int)

type Type

type Type struct {
	Name     string
	Scope    *Model
	Kind     Kind
	Indirect bool
	Category Category
	Extra    []*Type // [{key_type},{value_type}] for map, [{element_type}] for list or set
	HasNew   bool
}

func NewCategoryType

func NewCategoryType(typ *Type, cg Category) *Type

func NewEnumType

func NewEnumType(name string, cg Category) *Type

func NewFuncType

func NewFuncType(name string, cg Category) *Type

func NewOneofType

func NewOneofType(name string) *Type

func NewStructType

func NewStructType(name string, cg Category) *Type

func (*Type) IsBaseType

func (rt *Type) IsBaseType() bool

func (*Type) IsBinary

func (rt *Type) IsBinary() bool

func (*Type) IsSettable

func (rt *Type) IsSettable() bool

func (*Type) ResolveDefaultValue

func (rt *Type) ResolveDefaultValue() string

func (*Type) ResolveName

func (rt *Type) ResolveName(scope *Model) (string, error)

func (*Type) ResolveNameForTypedef

func (rt *Type) ResolveNameForTypedef(scope *Model) (string, error)

type TypeDef

type TypeDef struct {
	Scope *Model
	Alias string
	Type  *Type
}

type Variable

type Variable struct {
	Scope *Model
	Name  string
	Type  *Type
	Value Literal
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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