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


Golang structs.Map函数代码示例

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


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

示例1: Execute

func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	opts.Full = true
	containerName := resource.Params.(*paramsList).container
	allPages := resource.Params.(*paramsList).allPages
	pager := objects.List(command.Ctx.ServiceClient, containerName, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := objects.ExtractInfo(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, obj := range info {
			result[j] = structs.Map(&obj)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := objects.ExtractInfo(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, obj := range info {
				result[j] = structs.Map(&obj)
			}
			resource.Result = result
			if len(info) >= limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.WaitGroup.Add(1)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
开发者ID:hdansou,项目名称:rack,代码行数:48,代码来源:list.go

示例2: securityGroupRuleSingle

func securityGroupRuleSingle(rule *osSecurityGroupRules.SecGroupRule) map[string]interface{} {
	m := structs.Map(rule)

	m["SecurityGroupID"] = m["SecGroupID"]

	return m
}
开发者ID:hdansou,项目名称:rack,代码行数:7,代码来源:common.go

示例3: Execute

func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	allPages := resource.Params.(*paramsList).allPages
	pager := flavors.ListDetail(command.Ctx.ServiceClient, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := flavors.ExtractFlavors(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, flavor := range info {
			result[j] = structs.Map(flavor)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := flavors.ExtractFlavors(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, flavor := range info {
				result[j] = structs.Map(flavor)
			}
			resource.Result = result
			if len(info) >= opts.Limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
开发者ID:harshalhshah,项目名称:rack,代码行数:45,代码来源:list.go

示例4: Execute

func (command *commandCreate) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsCreate)
	volumeAttachment, err := osVolumeAttach.Create(command.Ctx.ServiceClient, params.serverID, params.opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(volumeAttachment)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:9,代码来源:create.go

示例5: volumeSingle

func volumeSingle(volume *volumes.Volume) map[string]interface{} {
	m := structs.Map(volume)
	for k, v := range m {
		if v == nil {
			m[k] = ""
		}
	}
	return m
}
开发者ID:hdansou,项目名称:rack,代码行数:9,代码来源:common.go

示例6: Execute

func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(keypair)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:9,代码来源:generate.go

示例7: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	flavorID := resource.Params.(*paramsGet).flavor
	flavor, err := flavors.Get(command.Ctx.ServiceClient, flavorID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(flavor)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:9,代码来源:get.go

示例8: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	imageID := resource.Params.(*paramsGet).image
	image, err := images.Get(command.Ctx.ServiceClient, imageID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(image)
}
开发者ID:hdansou,项目名称:rack,代码行数:9,代码来源:get.go

示例9: networkSingle

func networkSingle(network *osNetworks.Network) map[string]interface{} {
	m := structs.Map(network)
	m["Up"] = m["AdminStateUp"]
	m["Tenant ID"] = m["TenantID"]
	if subnets, ok := m["Subnets"].([]string); ok {
		m["Subnets"] = strings.Join(subnets, ",")
	}
	return m
}
开发者ID:hdansou,项目名称:rack,代码行数:9,代码来源:common.go

示例10: snapshotSingle

func snapshotSingle(snapshot *osSnapshots.Snapshot) map[string]interface{} {
	m := structs.Map(snapshot)
	if attachments := m["Attachments"].([]string); len(attachments) > 0 {
		m["Attachments"] = strings.Join(attachments, ",")
	} else {
		m["Attachments"] = ""
	}
	return m
}
开发者ID:hdansou,项目名称:rack,代码行数:9,代码来源:common.go

示例11: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerInfo, err := containers.Get(command.Ctx.ServiceClient, containerName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
}
开发者ID:hdansou,项目名称:rack,代码行数:10,代码来源:get.go

示例12: Execute

func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	c := command.Ctx.CLIContext
	if c.IsSet("json") || c.IsSet("csv") || c.GlobalIsSet("json") || c.GlobalIsSet("csv") {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
开发者ID:mrhillsman,项目名称:rack,代码行数:14,代码来源:generate.go

示例13: Execute

func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}

	if command.Ctx.OutputFormat == "json" || command.Ctx.OutputFormat == "csv" {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
开发者ID:hdansou,项目名称:rack,代码行数:14,代码来源:generate.go

示例14: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	objectName := resource.Params.(*paramsGet).object
	objectRaw := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil)
	objectInfo, err := objectRaw.Extract()
	if err != nil {
		resource.Err = err
		return
	}
	objectMetadata, err := objectRaw.ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(objectInfo)
	resource.Result.(map[string]interface{})["Name"] = objectName
	resource.Result.(map[string]interface{})["Metadata"] = objectMetadata
}
开发者ID:harshalhshah,项目名称:rack,代码行数:18,代码来源:get.go

示例15: serverSingle

func serverSingle(rawServer interface{}) map[string]interface{} {
	server, ok := rawServer.(*osServers.Server)
	if !ok {
		return nil
	}
	m := structs.Map(rawServer)
	m["Public IPv4"] = server.AccessIPv4
	m["Public IPv6"] = server.AccessIPv6
	m["Private IPv4"] = ""
	ips, ok := server.Addresses["private"].([]interface{})
	if ok || len(ips) > 0 {
		priv, ok := ips[0].(map[string]interface{})
		if ok {
			m["Private IPv4"] = priv["addr"]
		}
	}
	m["Flavor"] = server.Flavor["id"]
	m["Image"] = server.Image["id"]
	return m
}
开发者ID:hdansou,项目名称:rack,代码行数:20,代码来源:common.go


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