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


Golang schema.String函数代码示例

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


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

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: 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

示例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: 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

示例9: 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

示例10: 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

示例11: 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

示例12: importConstraintsV1

func importConstraintsV1(source map[string]interface{}) (*constraints, error) {
	fields := schema.Fields{
		"architecture":  schema.String(),
		"container":     schema.String(),
		"cpu-cores":     schema.Uint(),
		"cpu-power":     schema.Uint(),
		"instance-type": schema.String(),
		"memory":        schema.Uint(),
		"root-disk":     schema.Uint(),

		"spaces": schema.List(schema.String()),
		"tags":   schema.List(schema.String()),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"architecture":  "",
		"container":     "",
		"cpu-cores":     uint64(0),
		"cpu-power":     uint64(0),
		"instance-type": "",
		"memory":        uint64(0),
		"root-disk":     uint64(0),

		"spaces": schema.Omit,
		"tags":   schema.Omit,
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "constraints 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 &constraints{
		Version:       1,
		Architecture_: valid["architecture"].(string),
		Container_:    valid["container"].(string),
		CpuCores_:     valid["cpu-cores"].(uint64),
		CpuPower_:     valid["cpu-power"].(uint64),
		InstanceType_: valid["instance-type"].(string),
		Memory_:       valid["memory"].(uint64),
		RootDisk_:     valid["root-disk"].(uint64),

		Spaces_: convertToStringSlice(valid["spaces"]),
		Tags_:   convertToStringSlice(valid["tags"]),
	}, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:50,代码来源:constraints.go

示例13: importActionV1

func importActionV1(source map[string]interface{}) (*action, error) {
	fields := schema.Fields{
		"receiver":   schema.String(),
		"name":       schema.String(),
		"parameters": schema.StringMap(schema.Any()),
		"enqueued":   schema.Time(),
		"started":    schema.Time(),
		"completed":  schema.Time(),
		"status":     schema.String(),
		"message":    schema.String(),
		"results":    schema.StringMap(schema.Any()),
		"id":         schema.String(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"started":   time.Time{},
		"completed": time.Time{},
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "action v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	action := &action{
		Id_:         valid["id"].(string),
		Receiver_:   valid["receiver"].(string),
		Name_:       valid["name"].(string),
		Status_:     valid["status"].(string),
		Message_:    valid["message"].(string),
		Parameters_: valid["parameters"].(map[string]interface{}),
		Enqueued_:   valid["enqueued"].(time.Time).UTC(),
		Results_:    valid["results"].(map[string]interface{}),
	}

	started := valid["started"].(time.Time)
	if !started.IsZero() {
		started = started.UTC()
		action.Started_ = &started
	}
	completed := valid["completed"].(time.Time)
	if !started.IsZero() {
		completed = completed.UTC()
		action.Completed_ = &completed
	}
	return action, nil
}
开发者ID:bac,项目名称:juju,代码行数:48,代码来源:action.go

示例14: TestStringified

func (s *S) TestStringified(c *gc.C) {
	s.sch = schema.Stringified()

	out, err := s.sch.Coerce(true, aPath)
	c.Assert(err, gc.IsNil)
	c.Check(out, gc.Equals, "true")

	out, err = s.sch.Coerce(10, aPath)
	c.Assert(err, gc.IsNil)
	c.Check(out, gc.Equals, "10")

	out, err = s.sch.Coerce(1.1, aPath)
	c.Assert(err, gc.IsNil)
	c.Check(out, gc.Equals, "1.1")

	out, err = s.sch.Coerce("spam", aPath)
	c.Assert(err, gc.IsNil)
	c.Check(out, gc.Equals, "spam")

	_, err = s.sch.Coerce(map[string]string{}, aPath)
	c.Check(err, gc.ErrorMatches, ".* unexpected value .*")

	_, err = s.sch.Coerce([]string{}, aPath)
	c.Check(err, gc.ErrorMatches, ".* unexpected value .*")

	s.sch = schema.Stringified(schema.StringMap(schema.String()))

	out, err = s.sch.Coerce(map[string]string{"a": "b"}, aPath)
	c.Assert(err, gc.IsNil)
	c.Check(out, gc.Equals, `map[string]string{"a":"b"}`)
}
开发者ID:howbazaar,项目名称:schema,代码行数:31,代码来源:schema_test.go

示例15: 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


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