schemax

package
v0.0.0-...-4675295 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

README

descz 描述

主要用于记录序列化必要的信息。通过代码生成器生成。

  • 目标
    • 避免使用反射,增加了性能
    • 编辑器友好
    • 使用@schema生成描述
  • 声明类型
    • 结构
    • 枚举
  • 字段类型 fieldkind.Kind
  • 注意
    • 类只有一个父函数
    • 通常声明会保存在 descz.Set 中
    • 由于descz应用仅限于序列化,声明的ID冲突概率很低,因此,不使用长路径。声明ID采用 lastpkg.Name 的格式。例如 user.Login。
    • 如果遇到ID冲突,可通过 descz.NewDescriptionSet 自己管理

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDecl

func AddDecl(decl IDecl) (err error)

func AddDecls

func AddDecls(decls []IDecl) (err error)

func CheckObject

func CheckObject(obj datax.M, decl *ClassDecl) (err error)

如果是数字,会转化成正确的类型

func CheckType

func CheckType(valType IType, val interface{}) (err error)

如果是数字,会转化成正确的类型

func GetDeclByStructKey

func GetDeclByStructKey(st interface{}) string

func InitObj

func InitObj(obj datax.M, decl *ClassDecl) (err error)

func JustifyAnyType

func JustifyAnyType(ival interface{}, ftyp *AnyType) (interface{}, error)

func JustifyEnumType

func JustifyEnumType(ival interface{}, ftyp *EnumType) (interface{}, error)

func JustifyObject

func JustifyObject(obj datax.M, decl *ClassDecl) (result datax.M, err error)

JustifyObject 如果是数字,会转化成正确的类型

func ParseJson

func ParseJson(content string) (err error)

Types

type AnyType

type AnyType struct {
}

func (*AnyType) RefType

func (typ *AnyType) RefType() string

func (*AnyType) String

func (typ *AnyType) String() string

type ArrayType

type ArrayType struct {
	Elem IType
}

func (*ArrayType) RefType

func (typ *ArrayType) RefType() string

func (*ArrayType) String

func (typ *ArrayType) String() string

type BasicType

type BasicType struct {
	Kind basickind.Kind
}

func (*BasicType) RefType

func (typ *BasicType) RefType() string

func (*BasicType) String

func (typ *BasicType) String() string

type ClassDecl

type ClassDecl struct {
	//
	Namespace string
	//
	Name string
	//
	Parent string
	// 如果Kind==Struct
	Fields []*Field
	//
	Comments []string
	//
	Tags map[string]string
}

func ParseClass

func ParseClass(rtyp reflect.Type) *ClassDecl

func (*ClassDecl) GetAllField

func (decl *ClassDecl) GetAllField() (r []*Field)

GetAllField 获取类的属性字段,包括父类

func (*ClassDecl) GetField

func (decl *ClassDecl) GetField(name string) (f *Field)

func (*ClassDecl) GetIdent

func (decl *ClassDecl) GetIdent() string

func (*ClassDecl) GetName

func (decl *ClassDecl) GetName() string

func (*ClassDecl) GetNamespace

func (decl *ClassDecl) GetNamespace() string

func (*ClassDecl) GetParent

func (decl *ClassDecl) GetParent() *ClassDecl

func (*ClassDecl) RefType

func (decl *ClassDecl) RefType() string

type ClassType

type ClassType struct {
	Decl string
}

func (*ClassType) RefType

func (typ *ClassType) RefType() string

func (*ClassType) String

func (typ *ClassType) String() string

type EnumDecl

type EnumDecl struct {
	//
	Namespace string

	Comments []string
	//
	Name string
	//
	Kind int
	//
	Fields []*Field
}

func ParseEnum

func ParseEnum(val interface{}) *EnumDecl

golang不支持枚举类型,无法在运行时解析 如需枚举需求,可通过注解工具创建枚举代码

func (*EnumDecl) ConvertToValue

func (decl *EnumDecl) ConvertToValue(ival interface{}) (r interface{})

func (*EnumDecl) GetIdent

func (decl *EnumDecl) GetIdent() string

func (*EnumDecl) GetName

func (decl *EnumDecl) GetName() string

func (*EnumDecl) GetNamespace

func (decl *EnumDecl) GetNamespace() string

func (*EnumDecl) NameIndex

func (decl *EnumDecl) NameIndex(name string) int

func (*EnumDecl) NameToValue

func (decl *EnumDecl) NameToValue(name string) (r interface{})

func (*EnumDecl) NameToValueString

func (decl *EnumDecl) NameToValueString(name string) (r string)

func (*EnumDecl) RefType

func (decl *EnumDecl) RefType() string

func (*EnumDecl) ValueIndex

func (decl *EnumDecl) ValueIndex(val string) int

func (*EnumDecl) ValueToName

func (decl *EnumDecl) ValueToName(ival interface{}) (r string)

type EnumType

type EnumType struct {
	Decl string
}

func (*EnumType) RefType

func (typ *EnumType) RefType() string

func (*EnumType) String

func (typ *EnumType) String() string

type Field

type Field struct {
	Name string
	//
	Type IType
	// 如果Type=ClassType, 可通过设置{}建立新对象, 否则默认为nil
	// 如果Type=MapType, 可通过设置{}建立新对象, 否则默认为nil
	// 如果Type=BasicType/EnumType, Value为初始值
	Value string
	//
	Comments []string
	//
	Tags map[string]string
}

func (*Field) Alias

func (typ *Field) Alias() string

func (*Field) RefType

func (typ *Field) RefType() string

type FuncType

type FuncType struct {
	Args    []*Field
	Results []*Field
}

func (*FuncType) RefType

func (typ *FuncType) RefType() string

func (*FuncType) String

func (typ *FuncType) String() string

type IDecl

type IDecl interface {
	GetIdent() string
	GetName() string
	GetNamespace() string
	RefType() string
}

func CreateDecl

func CreateDecl(st reflect.Type) IDecl

func GetDeclByKey

func GetDeclByKey(key string) IDecl

func GetDeclByStruct

func GetDeclByStruct(st interface{}) IDecl

type IObject

type IObject interface {
	RefType() string
}

继承描述对象接口的实例,可避免使用反射获取类型信息,增加性能

type IType

type IType interface {
	String() string
}

type InterfaceDecl

type InterfaceDecl struct {
	//
	Namespace string

	Comments []string
	//
	Name string
	//
	Kind int
	//
	Fields []*Field
}

func (*InterfaceDecl) GetIdent

func (decl *InterfaceDecl) GetIdent() string

func (*InterfaceDecl) GetName

func (decl *InterfaceDecl) GetName() string

func (*InterfaceDecl) GetNamespace

func (decl *InterfaceDecl) GetNamespace() string

func (*InterfaceDecl) RefType

func (decl *InterfaceDecl) RefType() string

type MapType

type MapType struct {
	Key   IType
	Value IType
}

func (*MapType) RefType

func (typ *MapType) RefType() string

func (*MapType) String

func (typ *MapType) String() string

type UnsafeInfo

type UnsafeInfo struct {
	Offset uintptr
	Kind   reflect.Kind
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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