当前位置: 首页>>代码示例>>Golang>>正文


Golang system.Packed类代码示例

本文整理汇总了Golang中kego/io/system.Packed的典型用法代码示例。如果您正苦于以下问题:Golang Packed类的具体用法?Golang Packed怎么用?Golang Packed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Packed类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Unpack

func (v *CRule) 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/process/validate/tests", "@c"); err != nil {
		return err
	}
	if v.Rule == nil {
		v.Rule = new(system.Rule)
	}
	if err := v.Rule.Unpack(ctx, in, false); err != nil {
		return err
	}
	if field, ok := in.Map()["fail"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.Bool)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Fail = ob0
	}
	return nil
}
开发者ID:kego,项目名称:ke,代码行数:28,代码来源:generated.go

示例2: Unpack

func (v *ImageRule) 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", "@image"); err != nil {
		return err
	}
	if v.Rule == nil {
		v.Rule = new(system.Rule)
	}
	if err := v.Rule.Unpack(ctx, in, false); err != nil {
		return err
	}
	if field, ok := in.Map()["secure"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.Bool)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Secure = ob0
	}
	return nil
}
开发者ID:kego,项目名称:ke,代码行数:28,代码来源:generated.go

示例3: Unpack

func (v *Columns) 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/site", "columns"); err != nil {
		return err
	}
	if field, ok := in.Map()["columns"]; ok && field.Type() != system.J_NULL {
		if field.Type() != system.J_ARRAY {
			return fmt.Errorf("Unsupported json type %s found while unpacking into an array.", field.Type())
		}
		ob0 := []Section{}
		for i0 := range field.Array() {
			ob1, err := UnpackSection(ctx, field.Array()[i0])
			if err != nil {
				return err
			}
			ob0 = append(ob0, ob1)
		}
		v.Columns = ob0
	}
	return nil
}
开发者ID:kego,项目名称:ke,代码行数:29,代码来源:generated.go

示例4: UnpackFInterface

func UnpackFInterface(ctx context.Context, in system.Packed) (FInterface, error) {
	switch in.Type() {
	case system.J_MAP:
		i, err := system.UnpackUnknownType(ctx, in, true, "kego.io/process/validate/tests", "f")
		if err != nil {
			return nil, err
		}
		ob, ok := i.(FInterface)
		if !ok {
			return nil, fmt.Errorf("%T does not implement FInterface", i)
		}
		return ob, nil
	default:
		return nil, fmt.Errorf("Unsupported json type %s when unpacking into FInterface.", in.Type())
	}
}
开发者ID:kego,项目名称:ke,代码行数:16,代码来源:generated.go

示例5: UnpackLocalized

func UnpackLocalized(ctx context.Context, in system.Packed) (Localized, error) {
	switch in.Type() {
	case system.J_MAP:
		i, err := system.UnpackUnknownType(ctx, in, true, "kego.io/demo/demo5/translation", "localized")
		if err != nil {
			return nil, err
		}
		ob, ok := i.(Localized)
		if !ok {
			return nil, fmt.Errorf("%T does not implement Localized", i)
		}
		return ob, nil
	default:
		return nil, fmt.Errorf("Unsupported json type %s when unpacking into Localized.", in.Type())
	}
}
开发者ID:kego,项目名称:ke,代码行数:16,代码来源:generated.go

示例6: UnpackPageInterface

func UnpackPageInterface(ctx context.Context, in system.Packed) (PageInterface, error) {
	switch in.Type() {
	case system.J_MAP:
		i, err := system.UnpackUnknownType(ctx, in, true, "kego.io/demo/demo2", "page")
		if err != nil {
			return nil, err
		}
		ob, ok := i.(PageInterface)
		if !ok {
			return nil, fmt.Errorf("%T does not implement PageInterface", i)
		}
		return ob, nil
	default:
		return nil, fmt.Errorf("Unsupported json type %s when unpacking into PageInterface.", in.Type())
	}
}
开发者ID:kego,项目名称:ke,代码行数:16,代码来源:generated.go

示例7: UnpackSection

func UnpackSection(ctx context.Context, in system.Packed) (Section, error) {
	switch in.Type() {
	case system.J_MAP:
		i, err := system.UnpackUnknownType(ctx, in, true, "kego.io/demo/site", "section")
		if err != nil {
			return nil, err
		}
		ob, ok := i.(Section)
		if !ok {
			return nil, fmt.Errorf("%T does not implement Section", i)
		}
		return ob, nil
	default:
		return nil, fmt.Errorf("Unsupported json type %s when unpacking into Section.", in.Type())
	}
}
开发者ID:kego,项目名称:ke,代码行数:16,代码来源:generated.go

示例8: Unpack

func (v *MainRule) 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 v.Rule == nil {
		v.Rule = new(system.Rule)
	}
	if err := v.Rule.Unpack(ctx, in, false); err != nil {
		return err
	}
	return nil
}
开发者ID:kego,项目名称:ke,代码行数:18,代码来源:generated.go

示例9: Unpack

func (v *Simple) 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/demo5/translation", "simple"); err != nil {
		return err
	}
	if field, ok := in.Map()["text"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.String)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Text = ob0
	}
	return nil
}
开发者ID:kego,项目名称:ke,代码行数:22,代码来源:generated.go

示例10: Unpack

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/demo3/images", "photo"); err != nil {
		return err
	}
	if field, ok := in.Map()["url"]; ok && field.Type() != system.J_NULL {
		ob0 := new(system.String)
		if err := ob0.Unpack(ctx, field, false); err != nil {
			return err
		}
		v.Url = ob0
	}
	return nil
}
开发者ID:kego,项目名称:ke,代码行数:22,代码来源:generated.go

示例11: initialiseFields

func (n *Node) initialiseFields(ctx context.Context, in system.Packed, updateVal bool) error {

	valueFields := map[string]system.Packed{}
	if in != nil && in.Type() != system.J_NULL {
		valueFields = in.Map()
	}

	typeFields := map[string]*system.Field{}
	if err := extractFields(ctx, typeFields, n.Type); err != nil {
		return kerr.Wrap("LPWTOSATQE", err)
	}

	for name, typeField := range typeFields {
		rule := system.WrapRule(ctx, typeField.Rule)
		valueField, valueExists := valueFields[name]
		childNode := NewNode()
		if err := childNode.initialiseObjectField(ctx, n, rule, name, typeField.Origin); err != nil {
			return kerr.Wrap("ILIHBXGROP", err)
		}
		if err := childNode.AddToObject(ctx, n, rule, name, updateVal); err != nil {
			return kerr.Wrap("LJUGPMWNPD", err)
		}
		if valueExists {
			if err := childNode.setValue(ctx, valueField, false); err != nil {
				return kerr.Wrap("UWOTRJJVNK", err)
			}
		}
	}

	for name, _ := range valueFields {
		_, ok := typeFields[name]
		if !ok {
			return kerr.New("SRANLETJRS", "Extra field %s, %s", name, n.Path())
		}
	}

	return nil
}
开发者ID:kego,项目名称:ke,代码行数:38,代码来源:node.go

示例12: setValue

func (n *Node) setValue(ctx context.Context, in system.Packed, unpack bool) error {

	n.Missing = false

	objectType, err := extractType(ctx, in, n.Rule)
	if err != nil {
		return kerr.Wrap("MKMNOOYQJY", err)
	}
	if err := n.setType(ctx, objectType); err != nil {
		return kerr.Wrap("BCMOTEMUJE", err)
	}

	if n.Rule == nil && objectType != nil {
		n.Rule = system.WrapEmptyRule(ctx, objectType)
	}

	if in.Type() == system.J_MAP && n.Type.IsNativeObject() {
		// for objects and maps, Type() from the system.Packed is always J_MAP,
		// so we correct it for object types here.
		n.JsonType = system.J_OBJECT
	} else {
		n.JsonType = in.Type()
	}
	n.Null = in.Type() == system.J_NULL

	// validate json type
	//	if !n.Null && n.Type.NativeJsonType() != n.JsonType {
	//		return kerr.New("VEPLUIJXSN", "json type is %s but object type is %s", n.JsonType, n.Type.NativeJsonType())
	//	}

	if unpack {
		if n.Rule.Struct == nil {
			if err := system.Unpack(ctx, in, &n.Value); err != nil {
				return kerr.Wrap("CQMWGPLYIJ", err)
			}
		} else {
			t, err := n.Rule.GetReflectType()
			if err != nil {
				return kerr.Wrap("DQJDYPIANO", err)
			}

			var val reflect.Value
			if t.Kind() == reflect.Ptr {
				val = reflect.New(t.Elem())
			} else {
				val = reflect.New(t).Elem()
			}

			if err := system.UnpackRefelctValue(ctx, in, val); err != nil {
				return kerr.Wrap("PEVKGFFHLL", err)
			}

			n.Value = val.Interface()
		}
		n.setVal(reflect.ValueOf(n.Value))
	}

	switch n.Type.NativeJsonType(ctx) {
	case system.J_STRING:
		if in.Type() == system.J_MAP {
			n.ValueString = in.Map()["value"].String()
		} else {
			n.ValueString = in.String()
		}
	case system.J_NUMBER:
		if in.Type() == system.J_MAP {
			n.ValueNumber = in.Map()["value"].Number()
		} else {
			n.ValueNumber = in.Number()
		}
	case system.J_BOOL:
		if in.Type() == system.J_MAP {
			n.ValueBool = in.Map()["value"].Bool()
		} else {
			n.ValueBool = in.Bool()
		}
	case system.J_ARRAY:
		children := in.Array()
		for i, child := range children {
			childNode := NewNode()
			if err := childNode.InitialiseArrayItem(ctx, n, i); err != nil {
				return kerr.Wrap("XHQKQTNRJV", err)
			}
			if err := childNode.AddToArray(ctx, n, i, false); err != nil {
				return kerr.Wrap("VWWYPDIJKP", err)
			}
			if err := childNode.setValue(ctx, child, false); err != nil {
				return kerr.Wrap("KUCBPFFJNT", err)
			}
		}
	case system.J_MAP:
		n.Map = map[string]*Node{}
		children := in.Map()
		for name, child := range children {
			childNode := NewNode()
			if err := childNode.InitialiseMapItem(ctx, n, name); err != nil {
				return kerr.Wrap("TBNWBMJDIE", err)
			}
			if err := childNode.AddToMap(ctx, n, name, false); err != nil {
				return kerr.Wrap("HTOPDOKPRE", err)
//.........这里部分代码省略.........
开发者ID:kego,项目名称:ke,代码行数:101,代码来源:node.go

示例13: extractType

func extractType(ctx context.Context, in system.Packed, rule *system.RuleWrapper) (*system.Type, error) {

	parentInterface := rule != nil && rule.Parent != nil && rule.Parent.Interface
	ruleInterface := rule != nil && rule.Struct != nil && rule.Struct.Interface

	if parentInterface && ruleInterface {
		return nil, kerr.New("TDXTPGVFAK", "Can't have interface type and interface rule at the same time")
	}

	if rule != nil && rule.Parent != nil && !parentInterface && !ruleInterface {
		// If we have a rule with the parent, and it's not an interface, then
		// we just return the parent type of the rule.
		return rule.Parent, nil
	}

	// if the rule is nil (e.g. unpacking into an unknown type) or the type is
	// an interface, we ensure the input is a map
	if rule == nil || parentInterface {
		if in == nil {
			return nil, nil
		}
		switch in.Type() {
		case system.J_NULL:
			// item is nil, so we don't know the concrete type yet.
			return nil, nil
		case system.J_MAP:
			break
		default:
			return nil, kerr.New("DLSQRFLINL", "Input %s should be J_MAP if rule is nil or an interface type", in.Type())
		}
	}

	// if the rule is an interface rule, we ensure the input is a map or a native value
	if ruleInterface {
		if in == nil {
			return nil, nil
		}
		switch in.Type() {
		case system.J_NULL:
			// item is nil, so we don't know the concrete type yet.
			return nil, nil
		case system.J_MAP:
			break
		case system.J_STRING, system.J_NUMBER, system.J_BOOL:
			// if the input value is a native value, we will be unpacking into
			// the parent type of the rule
			return rule.Parent, nil
		default:
			return nil, kerr.New("SNYLGBJYTM", "Input %s should be J_MAP, J_STRING, J_NUMBER or J_BOOL if rule is interface rule", in.Type())
		}
	}

	ob := in.Map()
	typeField, ok := ob["type"]
	if !ok {
		return nil, kerr.New("HBJVDKAKBJ", "Input must have type field if rule is nil or an interface type")
	}
	var r system.Reference
	if err := r.Unpack(ctx, typeField, false); err != nil {
		return nil, kerr.Wrap("YXHGIBXCOC", err)
	}
	t, ok := r.GetType(ctx)
	if !ok {
		return nil, kerr.New("IJFMJJWVCA", "Could not find type %s", r.Value())
	}
	return t, nil
}
开发者ID:kego,项目名称:ke,代码行数:67,代码来源:node.go


注:本文中的kego/io/system.Packed类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。