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

Golang structs.Map函数代码示例

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

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



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

示例1: subnetSingle

func subnetSingle(subnet *osSubnets.Subnet) map[string]interface{} {
	m := structs.Map(subnet)

	tmpMap := make([]map[string]interface{}, len(m["AllocationPools"].([]osSubnets.AllocationPool)))
	for i, pool := range m["AllocationPools"].([]osSubnets.AllocationPool) {
		tmpMap[i] = structs.Map(pool)
	}

	m["AllocationPools"] = tmpMap

	/*
		m["Host Routes"] = m["HostRoutes"]
		delete(m, "HostRoutes")
		if hostRoutes, ok := m["Host Routes"].([]osSubnets.HostRoute); ok && len(hostRoutes) > 0 {
			fmt.Printf("hostRoutes: %+v\n", hostRoutes)
			out := []string{"Destination CIDR\tNext Hop"}
			for _, route := range hostRoutes {
				out = append(out, fmt.Sprintf("%s\t%s", route.DestinationCIDR, route.NextHop))
			}
			m["Host Routes"] = strings.Join(out, "\n")
		} else {
			m["Host Routes"] = ""
		}
	*/

	if nameServers, ok := m["DNSNameservers"].([]string); ok && len(nameServers) > 0 {
		m["DNSNameservers"] = strings.Join(nameServers, ", ")
	} else {
		m["DNSNameservers"] = ""
	}

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


示例2: portSingle

func portSingle(port *osPorts.Port) map[string]interface{} {
	m := structs.Map(port)

	tmpMap := make([]map[string]interface{}, len(m["FixedIPs"].([]osPorts.IP)))
	for i, pool := range m["FixedIPs"].([]osPorts.IP) {
		tmpMap[i] = structs.Map(pool)
	}

	m["FixedIPs"] = tmpMap

	m["Up"] = m["AdminStateUp"]

	/*
		if fixedIPs, ok := m["FixedIPs"].([]osPorts.IP); ok && len(fixedIPs) > 0 {
			out := []string{"Subnet ID\tIP Address"}
			for _, ip := range fixedIPs {
				out = append(out, fmt.Sprintf("%s\t%s", ip.SubnetID, ip.IPAddress))
			}
			m["FixedIPs"] = strings.Join(out, "\n")
		} else {
			m["FixedIPs"] = ""
		}
	*/

	if nameServers, ok := m["SecurityGroups"].([]string); ok && len(nameServers) > 0 {
		m["SecurityGroups"] = strings.Join(nameServers, "\n")
	} else {
		m["SecurityGroups"] = ""
	}

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


示例3: securityGroupSingle

func securityGroupSingle(securityGroup *osSecurityGroups.SecGroup) map[string]interface{} {
	m := structs.Map(securityGroup)

	tmpMap := make([]map[string]interface{}, len(m["Rules"].([]osSecurityGroupRules.SecGroupRule)))
	for i, pool := range m["Rules"].([]osSecurityGroupRules.SecGroupRule) {
		tmpMap[i] = map[string]interface{}{
			"ID":        pool.ID,
			"Direction": pool.Direction,
			"EtherType": pool.EtherType,
			"Protocol":  pool.Protocol,
		}
	}

	m["Rules"] = tmpMap

	/*
		if rules, ok := m["Rules"].([]osSecurityGroupRules.SecGroupRule); ok && len(rules) > 0 {
			out := []string{"ID\tDirection\tEtherType\tProtocol"}
			for _, rule := range rules {
				out = append(out, fmt.Sprintf("%s\t%s\t%s\t%s", rule.ID, rule.Direction, rule.EtherType, rule.Protocol))
			}
			m["Rules"] = strings.Join(out, "\n")
		} else {
			m["Rules"] = ""
		}
	*/

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


示例4: PreCSV

func (command *commandGetSchema) PreCSV(resource *handler.Resource) error {
	resource.Result = structs.Map(resource.Result)
	resource.FlattenMap("Attributes")
	resource.FlattenMap("Properties")
	resource.FlattenMap("SupportStatus")
	return nil
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:7,代码来源:getschema.go


示例5: securityGroupRuleSingle

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

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

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


示例6: resourceSingle

func resourceSingle(rawResource interface{}) map[string]interface{} {
	m := structs.Map(rawResource)
	switch resource := rawResource.(type) {
	case *osStackResources.Resource:
		if resource.CreationTime.Unix() != -62135596800 {
			m["CreationTime"] = resource.CreationTime
		} else {
			m["CreationTime"] = ""
		}
		if resource.UpdatedTime.Unix() != -62135596800 {
			m["UpdatedTime"] = resource.UpdatedTime
		} else {
			m["UpdatedTime"] = ""
		}
		if resource.Links != nil {
			links := make([]map[string]interface{}, len(resource.Links))
			for i, link := range resource.Links {
				links[i] = map[string]interface{}{
					"Href": link.Href,
					"Rel":  link.Rel,
				}
			}
			m["Links"] = links
		}
		return m
	}
	return nil

}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:29,代码来源:common.go


示例7: Execute

func (command *commandListEvents) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsListEvents)
	opts := params.opts
	stackName := params.stackName
	stackID := params.stackID
	resourceName := params.resourceName

	pager := stackevents.ListResourceEvents(command.Ctx.ServiceClient, stackName, stackID, resourceName, opts)

	pages, err := pager.AllPages()
	if err != nil {
		resource.Err = err
		return
	}
	info, err := osStackEvents.ExtractResourceEvents(pages)
	if err != nil {
		resource.Err = err
		return
	}
	result := make([]map[string]interface{}, len(info))
	for j, event := range info {
		result[j] = structs.Map(&event)
		result[j]["Time"] = event.Time
	}
	resource.Result = result
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:26,代码来源:listevents.go


示例8: 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.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:47,代码来源:list.go


示例9: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	buildids, err := buildinfo.Get(command.Ctx.ServiceClient).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(buildids)
}
开发者ID:pratikmallya,项目名称:rack,代码行数:8,代码来源:list.go


示例10: PreCSV

func (command *commandAbandon) PreCSV(resource *handler.Resource) error {
	resource.Result = structs.Map(resource.Result)
	resource.FlattenMap("Template")
	resource.FlattenMap("Files")
	resource.FlattenMap("Environment")
	resource.FlattenMap("Resources")
	return nil
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:8,代码来源:abandon.go


示例11: networkSingle

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


示例12: 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:satyamkotakonda,项目名称:rack,代码行数:9,代码来源:common.go


示例13: 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:satyamkotakonda,项目名称:rack,代码行数:9,代码来源:create.go


示例14: 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:satyamkotakonda,项目名称:rack,代码行数:9,代码来源:get.go


示例15: Execute

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


示例16: 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:smashwilson,项目名称:rack,代码行数:9,代码来源:get.go


示例17: 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:satyamkotakonda,项目名称:rack,代码行数:9,代码来源:common.go


示例18: Execute

func (command *commandValidate) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsValidate).opts

	result, err := stacktemplates.Validate(command.Ctx.ServiceClient, params).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(result)
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:10,代码来源:validate.go


示例19: Execute

func (command *commandGet) Execute(resource *handler.Resource) {
	info, err := buildinfo.Get(command.Ctx.ServiceClient).Extract()
	if err != nil {
		resource.Err = err
	}
	result := structs.Map(info)
	for k, v := range result {
		result[k] = v.(map[string]interface{})["Revision"]
	}
	resource.Result = result
}
开发者ID:satyamkotakonda,项目名称:rack,代码行数:11,代码来源:get.go


示例20: securityGroupSingle

func securityGroupSingle(securityGroup *osSecurityGroups.SecGroup) map[string]interface{} {
	m := structs.Map(securityGroup)

	if rules, ok := m["Rules"].([]osSecurityGroupRules.SecGroupRule); ok && len(rules) > 0 {
		out := []string{"ID\tDirection\tEtherType\tProtocol"}
		for _, rule := range rules {
			out = append(out, fmt.Sprintf("%s\t%s\t%s\t%s", rule.ID, rule.Direction, rule.EtherType, rule.Protocol))
		}
		m["Rules"] = strings.Join(out, "\n")
	} else {
		m["Rules"] = ""
	}

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang mapstructure.Decode函数代码示例发布时间:2022-05-28
下一篇:
Golang cli.App类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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