本文整理汇总了Golang中github.com/juju/schema.StringMap函数的典型用法代码示例。如果您正苦于以下问题:Golang StringMap函数的具体用法?Golang StringMap怎么用?Golang StringMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringMap函数的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: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例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: TestStringMap
func (s *S) TestStringMap(c *gc.C) {
s.sch = schema.StringMap(schema.Int())
out, err := s.sch.Coerce(map[string]interface{}{"a": 1, "b": int8(2)}, aPath)
c.Assert(err, gc.IsNil)
c.Assert(out, gc.DeepEquals, map[string]interface{}{"a": int64(1), "b": int64(2)})
out, err = s.sch.Coerce(42, aPath)
c.Assert(out, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "<path>: expected map, got int\\(42\\)")
out, err = s.sch.Coerce(nil, aPath)
c.Assert(out, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "<path>: expected map, got nothing")
out, err = s.sch.Coerce(map[int]int{1: 1}, aPath)
c.Assert(out, gc.IsNil)
c.Assert(err, gc.ErrorMatches, "<path>: expected string, got int\\(1\\)")
out, err = s.sch.Coerce(map[string]bool{"a": true}, aPath)
c.Assert(out, gc.IsNil)
c.Assert(err, gc.ErrorMatches, `<path>\.a: expected int, got bool\(true\)`)
// First path entry shouldn't have dots in an error message.
out, err = s.sch.Coerce(map[string]bool{"a": true}, nil)
c.Assert(out, gc.IsNil)
c.Assert(err, gc.ErrorMatches, `a: expected int, got bool\(true\)`)
}
开发者ID:howbazaar,项目名称:schema,代码行数:27,代码来源:schema_test.go
示例10: device_2_0
func device_2_0(source map[string]interface{}) (*device, error) {
fields := schema.Fields{
"resource_uri": schema.String(),
"system_id": schema.String(),
"hostname": schema.String(),
"fqdn": schema.String(),
"parent": schema.String(),
"owner": schema.String(),
"ip_addresses": schema.List(schema.String()),
"interface_set": schema.List(schema.StringMap(schema.Any())),
"zone": schema.StringMap(schema.Any()),
}
checker := schema.FieldMap(fields, nil) // no defaults
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "device 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.
interfaceSet, err := readInterfaceList(valid["interface_set"].([]interface{}), interface_2_0)
if err != nil {
return nil, errors.Trace(err)
}
zone, err := zone_2_0(valid["zone"].(map[string]interface{}))
if err != nil {
return nil, errors.Trace(err)
}
result := &device{
resourceURI: valid["resource_uri"].(string),
systemID: valid["system_id"].(string),
hostname: valid["hostname"].(string),
fqdn: valid["fqdn"].(string),
parent: valid["parent"].(string),
owner: valid["owner"].(string),
ipAddresses: convertToStringSlice(valid["ip_addresses"]),
interfaceSet: interfaceSet,
zone: zone,
}
return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:47,代码来源:device.go
示例11: 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
示例12: importEndpointV1
func importEndpointV1(source map[string]interface{}) (*endpoint, error) {
fields := schema.Fields{
"service-name": schema.String(),
"name": schema.String(),
"role": schema.String(),
"interface": schema.String(),
"optional": schema.Bool(),
"limit": schema.Int(),
"scope": schema.String(),
"unit-settings": schema.StringMap(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, "endpoint 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 := &endpoint{
ServiceName_: valid["service-name"].(string),
Name_: valid["name"].(string),
Role_: valid["role"].(string),
Interface_: valid["interface"].(string),
Optional_: valid["optional"].(bool),
Limit_: int(valid["limit"].(int64)),
Scope_: valid["scope"].(string),
UnitSettings_: make(map[string]map[string]interface{}),
}
for unitname, settings := range valid["unit-settings"].(map[string]interface{}) {
result.UnitSettings_[unitname] = settings.(map[string]interface{})
}
return result, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:39,代码来源:relation.go
示例13: readMachines
func readMachines(controllerVersion version.Number, source interface{}) ([]*machine, error) {
readFunc, err := getMachineDeserializationFunc(controllerVersion)
if err != nil {
return nil, errors.Trace(err)
}
checker := schema.List(schema.StringMap(schema.Any()))
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "machine base schema check failed")
}
valid := coerced.([]interface{})
return readMachineList(valid, readFunc)
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:14,代码来源:machine.go
示例14: readFile
func readFile(controllerVersion version.Number, source interface{}) (*file, error) {
readFunc, err := getFileDeserializationFunc(controllerVersion)
if err != nil {
return nil, errors.Trace(err)
}
checker := schema.StringMap(schema.Any())
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "file base schema check failed")
}
valid := coerced.(map[string]interface{})
return readFunc(valid)
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:14,代码来源:file.go
示例15: blockdevice_2_0
func blockdevice_2_0(source map[string]interface{}) (*blockdevice, error) {
fields := schema.Fields{
"resource_uri": schema.String(),
"id": schema.ForceInt(),
"name": schema.String(),
"model": schema.String(),
"path": schema.String(),
"used_for": schema.String(),
"tags": schema.List(schema.String()),
"block_size": schema.ForceUint(),
"used_size": schema.ForceUint(),
"size": schema.ForceUint(),
"partitions": schema.List(schema.StringMap(schema.Any())),
}
checker := schema.FieldMap(fields, nil)
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "blockdevice 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.
partitions, err := readPartitionList(valid["partitions"].([]interface{}), partition_2_0)
if err != nil {
return nil, errors.Trace(err)
}
result := &blockdevice{
resourceURI: valid["resource_uri"].(string),
id: valid["id"].(int),
name: valid["name"].(string),
model: valid["model"].(string),
path: valid["path"].(string),
usedFor: valid["used_for"].(string),
tags: convertToStringSlice(valid["tags"]),
blockSize: valid["block_size"].(uint64),
usedSize: valid["used_size"].(uint64),
size: valid["size"].(uint64),
partitions: partitions,
}
return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:49,代码来源:blockdevice.go
示例16: subnet_2_0
func subnet_2_0(source map[string]interface{}) (*subnet, error) {
fields := schema.Fields{
"resource_uri": schema.String(),
"id": schema.ForceInt(),
"name": schema.String(),
"space": schema.String(),
"gateway_ip": schema.OneOf(schema.Nil(""), schema.String()),
"cidr": schema.String(),
"vlan": schema.StringMap(schema.Any()),
"dns_servers": schema.OneOf(schema.Nil(""), schema.List(schema.String())),
}
checker := schema.FieldMap(fields, nil) // no defaults
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, errors.Annotatef(err, "subnet 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.
vlan, err := vlan_2_0(valid["vlan"].(map[string]interface{}))
if err != nil {
return nil, errors.Trace(err)
}
// Since the gateway_ip is optional, we use the two part cast assignment. If
// the cast fails, then we get the default value we care about, which is the
// empty string.
gateway, _ := valid["gateway_ip"].(string)
result := &subnet{
resourceURI: valid["resource_uri"].(string),
id: valid["id"].(int),
name: valid["name"].(string),
space: valid["space"].(string),
vlan: vlan,
gateway: gateway,
cidr: valid["cidr"].(string),
dnsServers: convertToStringSlice(valid["dns_servers"]),
}
return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:42,代码来源:subnet.go
示例17: readVLANs
func readVLANs(controllerVersion version.Number, source interface{}) ([]*vlan, error) {
checker := schema.List(schema.StringMap(schema.Any()))
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, errors.Annotatef(err, "vlan base schema check failed")
}
valid := coerced.([]interface{})
var deserialisationVersion version.Number
for v := range vlanDeserializationFuncs {
if v.Compare(deserialisationVersion) > 0 && v.Compare(controllerVersion) <= 0 {
deserialisationVersion = v
}
}
if deserialisationVersion == version.Zero {
return nil, errors.Errorf("no vlan read func for version %s", controllerVersion)
}
readFunc := vlanDeserializationFuncs[deserialisationVersion]
return readVLANList(valid, readFunc)
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:20,代码来源:vlan.go
示例18: readBootResources
func readBootResources(controllerVersion version.Number, source interface{}) ([]*bootResource, error) {
checker := schema.List(schema.StringMap(schema.Any()))
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "boot resource base schema check failed")
}
valid := coerced.([]interface{})
var deserialisationVersion version.Number
for v := range bootResourceDeserializationFuncs {
if v.Compare(deserialisationVersion) > 0 && v.Compare(controllerVersion) <= 0 {
deserialisationVersion = v
}
}
if deserialisationVersion == version.Zero {
return nil, NewUnsupportedVersionError("no boot resource read func for version %s", controllerVersion)
}
readFunc := bootResourceDeserializationFuncs[deserialisationVersion]
return readBootResourceList(valid, readFunc)
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:20,代码来源:bootresource.go
示例19: partition_2_0
func partition_2_0(source map[string]interface{}) (*partition, error) {
fields := schema.Fields{
"resource_uri": schema.String(),
"id": schema.ForceInt(),
"path": schema.String(),
"uuid": schema.String(),
"used_for": schema.String(),
"size": schema.ForceUint(),
"filesystem": schema.OneOf(schema.Nil(""), schema.StringMap(schema.Any())),
}
checker := schema.FieldMap(fields, nil)
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "partition 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.
var filesystem *filesystem
if fsSource := valid["filesystem"]; fsSource != nil {
filesystem, err = filesystem2_0(fsSource.(map[string]interface{}))
if err != nil {
return nil, errors.Trace(err)
}
}
result := &partition{
resourceURI: valid["resource_uri"].(string),
id: valid["id"].(int),
path: valid["path"].(string),
uuid: valid["uuid"].(string),
usedFor: valid["used_for"].(string),
size: valid["size"].(uint64),
filesystem: filesystem,
}
return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:41,代码来源:partition.go
示例20: Coerce
func (c cloudCredentialChecker) Coerce(v interface{}, path []string) (interface{}, error) {
out := CloudCredential{
AuthCredentials: make(map[string]Credential),
}
v, err := schema.StringMap(cloudCredentialValueChecker{}).Coerce(v, path)
if err != nil {
return nil, err
}
mapv := v.(map[string]interface{})
for k, v := range mapv {
switch k {
case "default-region":
out.DefaultRegion = v.(string)
case "default-credential":
out.DefaultCredential = v.(string)
default:
out.AuthCredentials[k] = v.(Credential)
}
}
return out, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:21,代码来源:credentials.go
注:本文中的github.com/juju/schema.StringMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论