• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang schema.FieldMap函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parseAllocateConstraintsResponse

func parseAllocateConstraintsResponse(source interface{}, machine *machine) (ConstraintMatches, error) {
	var empty ConstraintMatches
	matchFields := schema.Fields{
		"storage":    schema.StringMap(schema.ForceInt()),
		"interfaces": schema.StringMap(schema.ForceInt()),
	}
	matchDefaults := schema.Defaults{
		"storage":    schema.Omit,
		"interfaces": schema.Omit,
	}
	fields := schema.Fields{
		"constraints_by_type": schema.FieldMap(matchFields, matchDefaults),
	}
	checker := schema.FieldMap(fields, nil) // no defaults
	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return empty, WrapWithDeserializationError(err, "allocation constraints response schema check failed")
	}
	valid := coerced.(map[string]interface{})
	constraintsMap := valid["constraints_by_type"].(map[string]interface{})
	result := ConstraintMatches{
		Interfaces: make(map[string]Interface),
		Storage:    make(map[string]BlockDevice),
	}

	if interfaceMatches, found := constraintsMap["interfaces"]; found {
		for label, value := range interfaceMatches.(map[string]interface{}) {
			id := value.(int)
			iface := machine.Interface(id)
			if iface == nil {
				return empty, NewDeserializationError("constraint match interface %q: %d does not match an interface for the machine", label, id)
			}
			result.Interfaces[label] = iface
		}
	}

	if storageMatches, found := constraintsMap["storage"]; found {
		for label, value := range storageMatches.(map[string]interface{}) {
			id := value.(int)
			blockDevice := machine.PhysicalBlockDevice(id)
			if blockDevice == nil {
				return empty, NewDeserializationError("constraint match storage %q: %d does not match a physical block device for the machine", label, id)
			}
			result.Storage[label] = blockDevice
		}
	}
	return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:48,代码来源:controller.go


示例2: importAgentToolsV1

func importAgentToolsV1(source map[string]interface{}) (*agentTools, error) {
	fields := schema.Fields{
		"tools-version": schema.String(),
		"url":           schema.String(),
		"sha256":        schema.String(),
		"size":          schema.Int(),
	}
	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "agentTools v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	verString := valid["tools-version"].(string)
	toolsVersion, err := version.ParseBinary(verString)
	if err != nil {
		return nil, errors.Annotatef(err, "agentTools tools-version")
	}

	return &agentTools{
		Version_:      1,
		ToolsVersion_: toolsVersion,
		URL_:          valid["url"].(string),
		SHA256_:       valid["sha256"].(string),
		Size_:         valid["size"].(int64),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:machine.go


示例3: importStorageV1

func importStorageV1(source map[string]interface{}) (*storage, error) {
	fields := schema.Fields{
		"id":          schema.String(),
		"kind":        schema.String(),
		"owner":       schema.String(),
		"name":        schema.String(),
		"attachments": schema.List(schema.String()),
	}

	// Normally a list would have defaults, but in this case storage
	// should always have at least one attachment.
	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "storage v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.
	result := &storage{
		ID_:          valid["id"].(string),
		Kind_:        valid["kind"].(string),
		Owner_:       valid["owner"].(string),
		Name_:        valid["name"].(string),
		Attachments_: convertToStringSlice(valid["attachments"]),
	}

	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:storage.go


示例4: importPayloadV1

func importPayloadV1(source map[string]interface{}) (*payload, error) {
	fields := schema.Fields{
		"name":   schema.String(),
		"type":   schema.String(),
		"raw-id": schema.String(),
		"state":  schema.String(),
		"labels": schema.List(schema.String()),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"labels": schema.Omit,
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "payload v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})

	return &payload{
		Name_:   valid["name"].(string),
		Type_:   valid["type"].(string),
		RawID_:  valid["raw-id"].(string),
		State_:  valid["state"].(string),
		Labels_: convertToStringSlice(valid["labels"]),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:payload.go


示例5: versionedEmbeddedChecker

func versionedEmbeddedChecker(name string) schema.Checker {
	fields := schema.Fields{
		"version": schema.Int(),
	}
	fields[name] = schema.StringMap(schema.Any())
	return schema.FieldMap(fields, nil) // no defaults
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:serialization.go


示例6: importSpaceV1

func importSpaceV1(source map[string]interface{}) (*space, error) {
	fields := schema.Fields{
		"name":        schema.String(),
		"public":      schema.Bool(),
		"provider-id": schema.String(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"provider-id": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "space v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	return &space{
		Name_:       valid["name"].(string),
		Public_:     valid["public"].(bool),
		ProviderID_: valid["provider-id"].(string),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:space.go


示例7: importAddressV1

func importAddressV1(source map[string]interface{}) (*address, error) {
	fields := schema.Fields{
		"value":  schema.String(),
		"type":   schema.String(),
		"scope":  schema.String(),
		"origin": schema.String(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"scope":  "",
		"origin": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "address v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	return &address{
		Version: 1,
		Value_:  valid["value"].(string),
		Type_:   valid["type"].(string),
		Scope_:  valid["scope"].(string),
		Origin_: valid["origin"].(string),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:address.go


示例8: importRelationV1

func importRelationV1(source map[string]interface{}) (*relation, error) {
	fields := schema.Fields{
		"id":        schema.Int(),
		"key":       schema.String(),
		"endpoints": schema.StringMap(schema.Any()),
	}

	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "relation v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.
	result := &relation{
		Id_:  int(valid["id"].(int64)),
		Key_: valid["key"].(string),
	}

	endpoints, err := importEndpoints(valid["endpoints"].(map[string]interface{}))
	if err != nil {
		return nil, errors.Trace(err)
	}
	result.setEndpoints(endpoints)

	return result, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:29,代码来源:relation.go


示例9: importFilesystemAttachmentV1

func importFilesystemAttachmentV1(source map[string]interface{}) (*filesystemAttachment, error) {
	fields := schema.Fields{
		"machine-id":  schema.String(),
		"provisioned": schema.Bool(),
		"read-only":   schema.Bool(),
		"mount-point": schema.String(),
	}
	defaults := schema.Defaults{
		"mount-point": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "filesystemAttachment v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &filesystemAttachment{
		MachineID_:   valid["machine-id"].(string),
		Provisioned_: valid["provisioned"].(bool),
		ReadOnly_:    valid["read-only"].(bool),
		MountPoint_:  valid["mount-point"].(string),
	}
	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:filesystem.go


示例10: space_2_0

func space_2_0(source map[string]interface{}) (*space, error) {
	fields := schema.Fields{
		"resource_uri": schema.String(),
		"id":           schema.ForceInt(),
		"name":         schema.String(),
		"subnets":      schema.List(schema.StringMap(schema.Any())),
	}
	checker := schema.FieldMap(fields, nil) // no defaults
	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "space 2.0 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	subnets, err := readSubnetList(valid["subnets"].([]interface{}), subnet_2_0)
	if err != nil {
		return nil, errors.Trace(err)
	}

	result := &space{
		resourceURI: valid["resource_uri"].(string),
		id:          valid["id"].(int),
		name:        valid["name"].(string),
		subnets:     subnets,
	}
	return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:29,代码来源:space.go


示例11: importStatusV1

func importStatusV1(source map[string]interface{}) (StatusPoint_, error) {
	fields := schema.Fields{
		"value":   schema.String(),
		"message": schema.String(),
		"data":    schema.StringMap(schema.Any()),
		"updated": schema.Time(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"message": "",
		"data":    schema.Omit,
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return StatusPoint_{}, errors.Annotatef(err, "status v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	var data map[string]interface{}
	if sourceData, set := valid["data"]; set {
		data = sourceData.(map[string]interface{})
	}
	return StatusPoint_{
		Value_:   valid["value"].(string),
		Message_: valid["message"].(string),
		Data_:    data,
		Updated_: valid["updated"].(time.Time),
	}, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:33,代码来源:status.go


示例12: bootResource_2_0

func bootResource_2_0(source map[string]interface{}) (*bootResource, error) {
	fields := schema.Fields{
		"resource_uri": schema.String(),
		"id":           schema.ForceInt(),
		"name":         schema.String(),
		"type":         schema.String(),
		"architecture": schema.String(),
		"subarches":    schema.String(),
		"kflavor":      schema.String(),
	}
	checker := schema.FieldMap(fields, nil) // no defaults
	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, WrapWithDeserializationError(err, "boot resource 2.0 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &bootResource{
		resourceURI:  valid["resource_uri"].(string),
		id:           valid["id"].(int),
		name:         valid["name"].(string),
		type_:        valid["type"].(string),
		architecture: valid["architecture"].(string),
		subArches:    valid["subarches"].(string),
		kernelFlavor: valid["kflavor"].(string),
	}
	return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:30,代码来源:bootresource.go


示例13: TestFieldMapBasic

func (s *S) TestFieldMapBasic(c *gc.C) {
	fields := schema.Fields{
		"a": schema.Const("A"),
		"b": schema.Const("B"),
		"c": schema.Const("C"),
	}
	defaults := schema.Defaults{
		"b": schema.Omit,
		"c": "C",
	}
	s.sch = schema.FieldMap(fields, defaults)
	assertFieldMap(c, s.sch)

	out, err := s.sch.Coerce(map[string]interface{}{"a": "A", "b": "B", "d": "D"}, aPath)
	c.Assert(err, gc.IsNil)
	c.Assert(out, gc.DeepEquals, map[string]interface{}{"a": "A", "b": "B", "c": "C"})

	out, err = s.sch.Coerce(map[string]interface{}{"a": "A", "d": "D"}, aPath)
	c.Assert(err, gc.IsNil)
	c.Assert(out, gc.DeepEquals, map[string]interface{}{"a": "A", "c": "C"})

	out, err = s.sch.Coerce(123, aPath)
	c.Assert(err, gc.ErrorMatches, `<path>: expected map, got int\(123\)`)
	c.Assert(out, gc.Equals, nil)

	out, err = s.sch.Coerce(map[int]string{}, aPath)
	c.Assert(err, gc.ErrorMatches, `<path>: expected map\[string], got map\[int]string\(map\[int]string{}\)`)
	c.Assert(out, gc.Equals, nil)

	type strKey string
	out, err = s.sch.Coerce(map[strKey]string{"a": "A"}, aPath)
	c.Assert(err, gc.ErrorMatches, `<path>: expected map\[string], got map\[schema_test\.strKey]string\(map\[schema_test.strKey]string{"a":"A"}\)`)
	c.Assert(out, gc.Equals, nil)
}
开发者ID:howbazaar,项目名称:schema,代码行数:34,代码来源:schema_test.go


示例14: importOpenedPortsV1

func importOpenedPortsV1(source map[string]interface{}) (*openedPorts, error) {
	fields := schema.Fields{
		"subnet-id":    schema.String(),
		"opened-ports": schema.StringMap(schema.Any()),
	}

	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "opened-ports v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	ports, err := importPortRanges(valid["opened-ports"].(map[string]interface{}))
	if err != nil {
		return nil, errors.Trace(err)
	}
	result := &openedPorts{
		SubnetID_: valid["subnet-id"].(string),
	}
	result.setOpenedPorts(ports)
	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:ports.go


示例15: file_2_0

func file_2_0(source map[string]interface{}) (*file, error) {
	fields := schema.Fields{
		"resource_uri":      schema.String(),
		"filename":          schema.String(),
		"anon_resource_uri": schema.String(),
		"content":           schema.String(),
	}
	defaults := schema.Defaults{
		"content": "",
	}
	checker := schema.FieldMap(fields, defaults)
	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, WrapWithDeserializationError(err, "file 2.0 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	anonURI, err := url.ParseRequestURI(valid["anon_resource_uri"].(string))
	if err != nil {
		return nil, NewUnexpectedError(err)
	}

	result := &file{
		resourceURI:  valid["resource_uri"].(string),
		filename:     valid["filename"].(string),
		anonymousURI: anonURI,
		content:      valid["content"].(string),
	}
	return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:32,代码来源:file.go


示例16: importVolumeAttachmentV1

func importVolumeAttachmentV1(source map[string]interface{}) (*volumeAttachment, error) {
	fields := schema.Fields{
		"machine-id":  schema.String(),
		"provisioned": schema.Bool(),
		"read-only":   schema.Bool(),
		"device-name": schema.String(),
		"device-link": schema.String(),
		"bus-address": schema.String(),
	}
	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "volumeAttachment v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &volumeAttachment{
		MachineID_:   valid["machine-id"].(string),
		Provisioned_: valid["provisioned"].(bool),
		ReadOnly_:    valid["read-only"].(bool),
		DeviceName_:  valid["device-name"].(string),
		DeviceLink_:  valid["device-link"].(string),
		BusAddress_:  valid["bus-address"].(string),
	}
	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:29,代码来源:volume.go


示例17: readAPIVersion

func (c *controller) readAPIVersion(apiVersion version.Number) (set.Strings, version.Number, error) {
	parsed, err := c.get("version")
	if err != nil {
		return nil, apiVersion, errors.Trace(err)
	}

	// As we care about other fields, add them.
	fields := schema.Fields{
		"capabilities": schema.List(schema.String()),
	}
	checker := schema.FieldMap(fields, nil) // no defaults
	coerced, err := checker.Coerce(parsed, nil)
	if err != nil {
		return nil, apiVersion, WrapWithDeserializationError(err, "version response")
	}
	// For now, we don't append any subversion, but as it becomes used, we
	// should parse and check.

	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.
	capabilities := set.NewStrings()
	capabilityValues := valid["capabilities"].([]interface{})
	for _, value := range capabilityValues {
		capabilities.Add(value.(string))
	}

	return capabilities, apiVersion, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:29,代码来源:controller.go


示例18: importPortRangeV1

func importPortRangeV1(source map[string]interface{}) (*portRange, error) {
	fields := schema.Fields{
		"unit-name": schema.String(),
		"from-port": schema.Int(),
		"to-port":   schema.Int(),
		"protocol":  schema.String(),
	}

	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "port-range v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	return &portRange{
		UnitName_: valid["unit-name"].(string),
		FromPort_: int(valid["from-port"].(int64)),
		ToPort_:   int(valid["to-port"].(int64)),
		Protocol_: valid["protocol"].(string),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:ports.go


示例19: importLinkLayerDeviceV1

func importLinkLayerDeviceV1(source map[string]interface{}) (*linklayerdevice, error) {
	fields := schema.Fields{
		"provider-id":  schema.String(),
		"machine-id":   schema.String(),
		"name":         schema.String(),
		"mtu":          schema.Int(),
		"type":         schema.String(),
		"mac-address":  schema.String(),
		"is-autostart": schema.Bool(),
		"is-up":        schema.Bool(),
		"parent-name":  schema.String(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"provider-id": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "linklayerdevice v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	return &linklayerdevice{
		ProviderID_:  valid["provider-id"].(string),
		MachineID_:   valid["machine-id"].(string),
		Name_:        valid["name"].(string),
		MTU_:         uint(valid["mtu"].(int64)),
		Type_:        valid["type"].(string),
		MACAddress_:  valid["mac-address"].(string),
		IsAutoStart_: valid["is-autostart"].(bool),
		IsUp_:        valid["is-up"].(bool),
		ParentName_:  valid["parent-name"].(string),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:linklayerdevice.go


示例20: versionedChecker

func versionedChecker(name string) schema.Checker {
	fields := schema.Fields{
		"version": schema.Int(),
	}
	if name != "" {
		fields[name] = schema.List(schema.StringMap(schema.Any()))
	}
	return schema.FieldMap(fields, nil) // no defaults
}
开发者ID:bac,项目名称:juju,代码行数:9,代码来源:serialization.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang schema.ForceInt函数代码示例发布时间:2022-05-23
下一篇:
Golang schema.Bool函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap