modifyx

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: 6 Imported by: 0

README

modifyz 配置修正系统

  • 提供字段修正的功能,通常用于配置对象
  • 提供的配置修正包括 加成和修正
  • 配置修正对象只在初始化时赋值
  • map和数组的内容无法通过修正增加或者减少,配置修正只对已存在的值进行修正
  • 配置修正不支持any类型的修正

优化

  • 经过测试,使用数组保存数据,比map性能高很多,后期可考虑这个方向的优化
  • 如果采用数组保存数据,配置文件会比较麻烦,在编辑器完成后考虑
  • 采用数组需要字段数量,预创建数组,因此,需要descz的支持

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseKey

func ParseKey(key string) (kind, id string)

func RegisterType

func RegisterType(name string, creator func(object IObject) IObject)

Types

type A

type A = []interface{}

type Array

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

修正对象 如果需要在运行时,替换源的数据,可通过设置runtime实现

func (*Array) Dispose

func (s *Array) Dispose()

func (*Array) RefBool

func (s *Array) RefBool(index int) bool

修正后的整型

func (*Array) RefFloat64

func (s *Array) RefFloat64(index int) float64

修正后的浮点型

func (*Array) RefInt

func (s *Array) RefInt(index int) int

修正后的整型

func (*Array) RefLength

func (s *Array) RefLength() int

func (*Array) RefObject

func (s *Array) RefObject(index int) (r IObject)

func (*Array) RefOrigin

func (s *Array) RefOrigin(index int) interface{}

获取原始数据指定的字段

func (*Array) RefOriginBool

func (s *Array) RefOriginBool(index int) bool

func (*Array) RefOriginFloat

func (s *Array) RefOriginFloat(index int) float64

func (*Array) RefOriginInt

func (s *Array) RefOriginInt(index int) int

func (*Array) RefString

func (s *Array) RefString(index int) (val string)

func (*Array) RefUint

func (s *Array) RefUint(index int) (val uint)

type IArray

type IArray interface {
	RefInt(index int) (val int)
	RefUint(index int) (val uint)
	RefFloat64(index int) (val float64)
	RefString(index int) (val string)
	RefBool(index int) (val bool)
	RefObject(index int) (r IObject)
	RefLength() int
}

type IModify

type IModify interface {
	// 被修正的字段路径
	Path() string
	// 修正是否生效
	Valid(ctx interface{}) bool
	// 修正后的值
	Value(ctx interface{}, origin interface{}) (last interface{})
}

type IObject

type IObject interface {
	RefOrigin(field string) interface{}
	RefInt(field string) (val int)
	RefUint(field string) (val uint)
	RefFloat64(field string) (val float64)
	RefString(field string) (val string)
	RefBool(field string) (val bool)
	RefMap(field string) (r IObject)
	RefObject(field string) (r IObject)
	RefArray(field string) (r IArray)
	RefIsNil() bool
	RefKeys() (r []string)
	RefLength() int
	RefClassCreator(field string, creator func(object IObject) IObject)
	RefAnyType() string
}

type IRoot

type IRoot interface {
	IObject

	RefClassId() string
	// Kind/Id
	RefClassKey() string
	RefClassCatalog() string
	RefClassType() string
	RefDispose()
	// 设置修正的默认的上下文
	// 如果运行时需要指定的上下文,可通过 RefSource直接操作数据源
	RefSetContext(ctx interface{})
	RefSource() *Source
}

type M

type M = map[string]interface{}

type Object

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

修正对象 如果需要在运行时,替换源的数据,可通过设置runtime实现

func NewObject

func NewObject(root *Root) (obj *Object)

新建一个对象

func (*Object) Dispose

func (s *Object) Dispose()

func (*Object) RefAny

func (s *Object) RefAny(field string) (val interface{})

func (*Object) RefAnyType

func (s *Object) RefAnyType() string

func (*Object) RefArray

func (s *Object) RefArray(field string) (r IArray)

func (*Object) RefBool

func (s *Object) RefBool(field string) bool

修正后的整型

func (*Object) RefClassCreator

func (s *Object) RefClassCreator(field string, creator func(object IObject) IObject)

func (*Object) RefFloat64

func (s *Object) RefFloat64(field string) float64

修正后的浮点型

func (*Object) RefInt

func (s *Object) RefInt(field string) int

修正后的整型

func (*Object) RefIsNil

func (s *Object) RefIsNil() bool

func (*Object) RefKeys

func (s *Object) RefKeys() (r []string)

func (*Object) RefLength

func (s *Object) RefLength() int

func (*Object) RefMap

func (s *Object) RefMap(field string) (r IObject)

func (*Object) RefObject

func (s *Object) RefObject(field string) (r IObject)

func (*Object) RefOrigin

func (s *Object) RefOrigin(field string) interface{}

获取原始数据指定的字段

func (*Object) RefOriginBool

func (s *Object) RefOriginBool(field string) bool

func (*Object) RefOriginFloat

func (s *Object) RefOriginFloat(field string) float64

func (*Object) RefOriginInt

func (s *Object) RefOriginInt(field string) int

func (*Object) RefString

func (s *Object) RefString(field string) (val string)

func (*Object) RefUint

func (s *Object) RefUint(field string) (val uint)

type Root

type Root struct {
	*Object
	// contains filtered or unexported fields
}

func NewRoot

func NewRoot(source *Source) *Root

func (*Root) RefClassCatalog

func (s *Root) RefClassCatalog() string

func (*Root) RefClassId

func (s *Root) RefClassId() string

func (*Root) RefClassKey

func (s *Root) RefClassKey() string

func (*Root) RefClassType

func (s *Root) RefClassType() string

func (*Root) RefDispose

func (s *Root) RefDispose()

func (*Root) RefSetContext

func (s *Root) RefSetContext(ctx interface{})

func (*Root) RefSource

func (s *Root) RefSource() *Source

type Source

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

数据源 通常加载后,数据源不可变,作为配置文件的映射 采用数据源的目的是为了避免数据的克隆影响性能,毕竟需要修正的地方有限

func NewSource

func NewSource() *Source

className = origin["_type"]

func NewSourceWith

func NewSourceWith(data datax.M) *Source

func (*Source) AddModify

func (p *Source) AddModify(val IModify)

co.CModify

func (*Source) ClassCatalog

func (s *Source) ClassCatalog() string

func (*Source) ClassId

func (s *Source) ClassId() string

func (*Source) ClassKey

func (s *Source) ClassKey() string

func (*Source) ClassType

func (s *Source) ClassType() string

func (*Source) Clone

func (s *Source) Clone() (r *Source)

func (*Source) Dispose

func (s *Source) Dispose()

func (*Source) Get

func (s *Source) Get(ctx interface{}, path string) interface{}

func (*Source) GetOrigin

func (s *Source) GetOrigin(path string) interface{}

func (*Source) IsNil

func (s *Source) IsNil(path string) bool

func (*Source) Length

func (s *Source) Length(path string) int

获取 map或者array的长度,需要先判断 IsNil

func (*Source) MapKeys

func (s *Source) MapKeys(path string) []string

func (*Source) SetClassId

func (s *Source) SetClassId(val string)

Jump to

Keyboard shortcuts

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