示例#1
0
文件: node.go 项目: kego/ke
func (n *Node) initialiseCollectionItem(ctx context.Context, parent *Node, key string, index int) error {
	n.resetAllValues()
	n.Parent = parent
	n.Index = index
	n.Key = key
	n.Missing = false

	var collectionRule *system.RuleWrapper
	if n.Parent.Type.Alias != nil {
		collectionRule = system.WrapRule(ctx, n.Parent.Type.Alias)
	} else {
		collectionRule = parent.Rule
	}
	rule, err := collectionRule.ItemsRule()
	if err != nil {
		return kerr.Wrap("SBJVMGUOOA", err)
	}
	n.Rule = rule

	t, err := extractType(ctx, system.Pack(nil), rule)
	if err != nil {
		return kerr.Wrap("EQNRHQWXFJ", err)
	}

	if err := n.setType(ctx, t); err != nil {
		return kerr.Wrap("UPAQMUGDNH", err)
	}

	return nil
}
示例#2
0
文件: node_test.go 项目: kego/ke
func TestNode_extractType(t *testing.T) {
	r := &system.RuleWrapper{
		Struct: &system.Rule{Interface: true},
		Parent: &system.Type{Interface: true},
	}
	_, err := extractType(context.Background(), system.Pack(nil), r)
	assert.IsError(t, err, "TDXTPGVFAK")

	ty, err := extractType(context.Background(), nil, nil)
	require.NoError(t, err)
	assert.Nil(t, ty)

	r = &system.RuleWrapper{
		Parent: &system.Type{Interface: true},
	}
	_, err = extractType(context.Background(), system.Pack(""), r)
	assert.IsError(t, err, "DLSQRFLINL")

	r = &system.RuleWrapper{
		Struct: &system.Rule{Interface: true},
	}
	ty, err = extractType(context.Background(), nil, r)
	require.NoError(t, err)
	assert.Nil(t, ty)

	r = &system.RuleWrapper{
		Struct: &system.Rule{Interface: true},
	}
	_, err = extractType(context.Background(), system.MustPackString(`[""]`), r)
	assert.IsError(t, err, "SNYLGBJYTM")

	_, err = extractType(context.Background(), system.MustPackString(`{}`), nil)
	assert.IsError(t, err, "HBJVDKAKBJ")

	r = &system.RuleWrapper{
		Parent: &system.Type{Interface: true},
	}
	_, err = extractType(context.Background(), system.MustPackString(`{}`), r)
	assert.IsError(t, err, "HBJVDKAKBJ")

	cb := tests.Context("a.b/c").Sempty()
	_, err = extractType(cb.Ctx(), system.MustPackString(`{"type": "a"}`), nil)
	assert.IsError(t, err, "IJFMJJWVCA")

}
示例#3
0
文件: generated.go 项目: kego/ke
func (v *Photo) Unpack(ctx context.Context, in system.Packed, iface bool) error {
	if in == nil || in.Type() == system.J_NULL {
		return nil
	}
	if v.Object == nil {
		v.Object = new(system.Object)
	}
	if err := v.Object.Unpack(ctx, in, false); err != nil {
		return err
	}
	if err := v.Object.InitializeType("kego.io/demo/common/images", "photo"); err != nil {
		return err
	}
	if field, ok := in.Map()["path"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.String)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Path = ob0
	}
	if field, ok := in.Map()["protocol"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.String)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Protocol = ob0
	} else {
		ob0 := new(system.String)
		if err := ob0.Unpack(ctx, system.Pack("http"), false); err != nil {
			return err
		}
		v.Protocol = ob0
	}
	if field, ok := in.Map()["server"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.String)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Server = ob0
	}
	if field, ok := in.Map()["size"]; ok && field.Type() != system.J_NULL {
		ob0 := new(units.Rectangle)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Size = ob0
	}
	return nil
}
示例#4
0
文件: node.go 项目: kego/ke
func (n *Node) initialiseObjectField(ctx context.Context, parent *Node, rule *system.RuleWrapper, key string, origin *system.Reference) error {

	n.resetAllValues()
	n.Parent = parent
	n.Rule = rule
	n.Key = key
	n.Origin = origin

	t, err := extractType(ctx, system.Pack(nil), rule)
	if err != nil {
		return kerr.Wrap("RBDBRRUVMM", err)
	}

	if err := n.setType(ctx, t); err != nil {
		return kerr.Wrap("UOCRQYMGHR", err)
	}

	return nil

}
示例#5
0
文件: node.go 项目: kego/ke
func (n *Node) SetValueString(ctx context.Context, value string) error {
	if err := n.SetValueUnpack(ctx, system.Pack(value)); err != nil {
		return kerr.Wrap("GAMJNECRUW", err)
	}
	return nil
}
示例#6
0
文件: node.go 项目: kego/ke
func (n *Node) SetValueBool(ctx context.Context, value bool) error {
	if err := n.SetValueUnpack(ctx, system.Pack(value)); err != nil {
		return kerr.Wrap("AWRMEACQWR", err)
	}
	return nil
}
示例#7
0
文件: node.go 项目: kego/ke
func (n *Node) SetValueNumber(ctx context.Context, value float64) error {
	if err := n.SetValueUnpack(ctx, system.Pack(value)); err != nil {
		return kerr.Wrap("SOJGUGHXSX", err)
	}
	return nil
}